Launch Docker Container
To launch a new Docker container using below command. This will start a new container and provide you access of that container with /bin/bash shell.# docker run [OPTIONS] <IMAGE NAME> [COMMAND] [ARG...]For example below command will create new docker container using image named “ubuntu”. To list all available images use <orange>docker images</orange> command.
# docker run -i -t ubuntu /bin/bashTo exit from docker container type
List Docker Containers
After existing from Docker container, execute below command to list all running containers.# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2582758af13 ubuntu "/bin/bash" 2 hours ago Up 2 hours first_ubuntuBy default Above command will list only running containers. To list all containers (including stopped container) use following command.
# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f2582758af13 ubuntu "/bin/bash" 2 hours ago Up 2 hours first_ubuntu 6b5b5a969241 centos "/bin/bash" 2 days ago Exited (0) 24 hours ago ubuntu-web
Start/Stop/Attach Container
You can start, stop or attach to any containers with following commands. To start container use following command.# docker start <To stop container use following command.CONTAINER ID|NAME >
# docker stop <To attach to currently running container use following command.CONTAINER ID|NAME >
# docker attach <CONTAINER ID|NAME >
Drop Docker Container
Before deleting any container make sure that container is stopped. You can use ‘docker ps -a’ command to list status of containers. If container is still running first stop that container using given commands in above step.Now use following command to delete single or multiple containers use following command.
# docker rm <You can also delete all stopped containers at once using following command.CONTAINER ID|NAME > <CONTAINER ID|NAME >
# docker rm $(docker ps -a -q)
Comments
Post a Comment