# start a new container
docker container run --publish 80:80 nginx
# use the --detach option to run nginx in background
# list running containers
docker container ls
# old: docker ps
# also accepts the -a option
# stop a container
docker container stop 123
# the number at the end must be enough to be an unique ID
Note: docker container run
always start a new container. Use docker container start
to start an existing stopped one.
Starting a container with a custom name: use the --name containerName
option.
docker container run --publish 80:80 --detach --name webhost nginx
# see the logs:
docker container logs webhost
# see the running processes
docker container top webhost
Removing containers:
docker container rm 123 456 789
# use 'rm -f' to force removal
docker container run nginx
You can changes the defaults via command line arguments:
docker container run --publish 8080:80 --name webhost -d nginx:1.11 nginx -T
# --publish 8080:80 # change host listening port
# nginx:1.11 # change version of image
# nginx -T # change CMD to be launched on start