To create docker images and containers soon, follow the below-listed commands, steps, and requirements to create a docker file, docker image, and the container.
Create a new directory by using mkdir
~# mkdir myimages
Now, change the directory into my images.
~# cd myimages/
Use the touch command to create an empty Docker file.
# touch Docker file
Now, enter the below content in that file.
Build the image by using the Docker file with the tag name at the present location.
We can verify the Docker image now.
To delete a specific image.
For deleting all images at a time.
# docker rmi $ (docker images -q) -f
To know your image id.
# docker images -q
Note: If you want to remove images, you must remove containers first.
To create a new container with the base image using the following command.
# docker run -name <name of the container> -d -p 8081:8080 <image_name>
Now, the Container output will be displayed like this.
To list out the running containers, perform the below commands:
To remove a specific container.
To remove all the containers at a time.
To enter into a running container.
# docker exec -it <containerID> /bin/bash
We can start and stop the containers by using the following commands:
# docker start <ContainerID>
# docker stop <ContainerID>
Thus, the above steps, commands, and images describe the successful creation of docker images and containers easier than ever. Hence, the docker creation simplifies the existing and new tasks simpler than a usual one.