Utilizing Pulled Docker Images
Running a Docker Container
Once you have pulled a Docker image, you can use it to create and run a Docker container. To do this, you can use the docker run
command, specifying the image name and any additional options you need.
docker run -it ubuntu:22.04 /bin/bash
This will start a new container based on the Ubuntu 22.04 image and open an interactive shell inside the container.
Listing Running Containers
You can use the docker ps
command to list all the running Docker containers on your system.
docker ps
Stopping and Removing Containers
To stop a running container, you can use the docker stop
command, followed by the container ID or name.
docker stop my-container
To remove a stopped container, you can use the docker rm
command.
docker rm my-container
Building Custom Docker Images
In addition to using pre-built Docker images, you can also create your own custom images using a Dockerfile. A Dockerfile is a text file that contains a set of instructions for building a Docker image.
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
This Dockerfile will create a new Docker image based on the Ubuntu 22.04 image, install the Nginx web server, expose port 80, and start the Nginx server when the container is run.
You can build this image using the docker build
command:
docker build -t my-nginx-image .
Pushing Custom Images to a Registry
Once you have built a custom Docker image, you can push it to a Docker registry so that it can be shared and used by others.
docker push my-private-registry.com/my-nginx-image:latest
Conclusion
In this section, you have learned how to run Docker containers, manage running containers, and build and push your own custom Docker images. Utilizing Docker images is the key to building and deploying applications using Docker.