Overview
Docker has become a very commonly used tool for running applications deployed as containers.
This article lists 5 quick and easy docker tasks that you can complete in just a few minutes.
Whether you’re a beginner or just trying to refresh on your docker skills, these tasks will help you to get up and running with Docker very quickly
A container is one which executes. A container is a running image.
So, the most basic docker task is running a container from an image.
To run a container, we need a Docker image, which is a pre-built environment that you can use to run applications.
To run a container, simply use the docker run
command and specify the name of the image you want to run as shown below
docker run <imageid>
You can provide image id or its path and tag info. You can get both these values with docker images
command.
2. Checking container status
After running a container, we would also require checking its status to see if it’s running correctly.
To check the status of a container, use the docker ps
command
docker ps
ps
command, by default lists only running containers.
If you want to see all containers, then use it with -a
flag as below
docker ps -a
3. Stopping container
If you want to stop a running docker container, you can use the docker stop
command and specify the name or ID of the container as below
// stop with name docker stop my_container // stop with id docker stop hdgf2dhfdh3s
A stopped container can be started again using docker run
command mentioned above.
To remove a container, you can use the
docker rm
command and specify the name or ID of the container as below // stop with name docker rm my_container // stop with id docker rm hdgf2dhfdh3s
When you remove a container, docker will delete the container, its configuration, and any data stored in the container.
Removing a container has no effect over the image that was used to create the container.
Same image can be used to create the container once again after removal.
5. Exposing port
An application inside a docker container runs on a specific port.
But, this port is not accessible outside the container, even on the host machine on which the container is running.
To make the port accessible, we need to expose it. We can also expose a port other than the container port.
To expose a port in docker, you’ll need to use the -p
or --publish
flag when running a container. For example, to expose port 80 in a container, you can use the following command
docker run -p 9090:8080 my_image
This command maps port 8080 in the container to port 9090 on the host machine, allowing you to access the exposed port from outside the container.
That is all on this getting started guide with docker.
Hope the article was useful.