PART-1: Basic docker commands
* Let's suppose you have built an image.
Display list of your docker images:
Output:
As you can see image name is
To run the image:
The above command runs the docker image. The newly created processs by
host, and the second port
Now to see list of your containers use
From here you can see the ID of your container which is equal to
ontainer (login into container):
if you want to connect to the stdout of your container use
*** IF you are attached to a container and press ^c afterward, the container will be stopped.
If you want to stop a container:
It prints out container id
#docker #commands #docker_part1 #basic #container #devops
* Let's suppose you have built an image.
Display list of your docker images:
docker images
Output:
REPOSITORY TAG IMAGE ID CREATED SIZE
py_app latest baa470dc5609 3 weeks ago 591MB
As you can see image name is
py_app
.To run the image:
docker run -it -d -p 8085:8084 py_app
The above command runs the docker image. The newly created processs by
docker run
from your py_app
image is called a container
. -d
runs the image as a daemon and print the container id to your console:$ docker run -it -d -p 8085:8084 py_app
d612ffbd9d560158f1c64997f9a8877243cdf4288c11010298df80b10cfaff5e
-p
exposes the port on your docker file to the port on your host machine. The first port 8085
is the port on yourhost, and the second port
8084
is the port on your docker file.Now to see list of your containers use
docker ps
:docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d612ffbd9d56 py_app "python app.py" 10 minutes ago Up 10 minutes goofy_hopper
From here you can see the ID of your container which is equal to
d612ffbd9d56
. IF you want to have a shell on your container (login into container):
docker exec -it d612ffbd9d56 bash
root@moby:/app#
if you want to connect to the stdout of your container use
attach
, it does not necessary give you a shell:docker attach d612ffbd9d56
*** IF you are attached to a container and press ^c afterward, the container will be stopped.
If you want to stop a container:
$ docker stop d612ffbd9d56
d612ffbd9d56
It prints out container id
d612ffbd9d56
and stop the container. If you enter docker ps
you should not see the container.#docker #commands #docker_part1 #basic #container #devops