Table of Contents
docker ps
docker ps -a
Start a container using the image nginx
with host port 8080
mapped to container port 80
and name it try_nginx
:
docker run --name try_nginx -p 8080:80 nginx
Start a container using the image ubuntu
and name it try_ubuntu
(nothing happens since no command is given):
docker run --name try_ubuntu ubuntu
Start a container in the background using the image nginx
with host port 8080
mapped to container port 80
and name it try_nginx
:
docker run -d --name try_nginx -p 8080:80 nginx
-d
,--detach
: Run container in background and print container ID
Start a container using the image ubuntu
, and delete it after the command echo
finishes:
docker run --rm ubuntu echo "Hello World"
--rm
: Automatically remove the container when it exits
Start a container using the image nginx
, start an interactive shell instead of running the HTTP server:
docker run --rm -it --entrypoint /bin/bash nginx
--rm
: Automatically remove the container when it exits
-i
,--interactive
: Keep STDIN open even if not attached
-t
,--tty
: Allocate a pseudo-TTY
--entrypoint string
: Overwrite the default ENTRYPOINT of the image
Start an interactive shell in the running container try_nginx
:
docker exec -it try_nginx /bin/bash
Run the ps
command in the running container try_nginx
:
docker exec try_nginx ps
Start the container try_nginx
:
docker start try_nginx
Stop the container ac6aa090558c
:
docker stop ac6aa090558c
Remove the container try_ubuntu
:
docker rm try_ubuntu
docker images
Alternative spelling:
docker image ls
Download (or update) the image ubuntu
:
docker pull ubuntu
Download (or update) the trusty
tag of the image ubuntu
:
docker pull ubuntu:trusty
HTML result:
https://hub.docker.com/_/ubuntu/
JSON result:
https://registry.hub.docker.com/v1/repositories/ubuntu/tags
Remove the image ubuntu
:
docker rmi ubuntu
Alternative spelling:
docker image rm ubuntu