How to run Ubuntu system in docker

This article takes Ubuntu system as an example to share with you how to search image, start image and build container, start container, close container and other docker usage in docker.

Docker pulls and runs an image

1. Search Ubuntu image

➜  ~ docker search ubuntu

Select the image with the most stars.

docker search
search Search the Docker Hub for images

2. Pull Ubuntu image

➜  ~ docker pull ubuntu

➜  ~ docker image list
# OR
➜  ~ docker images

3. Run the image and build the container

➜  ~ docker run ubuntu /bin/bash
➜  ~ docker ps
# OR
➜  ~ docker container ls

Enter the command docker ps or docker container ls to view the running container.

The list is empty because the container will exit automatically after the command is executed. 

Use the command docker ps -a or docker container ls -a to view the container used and display the status of the container.

➜  ~ docker container ls -a
# OR
➜  ~ docker ps -a

docker ps
ps List containers

docker ps -a
-a
Show all containers

Docker keeps the image running in the background

1. Start a container and run it in the background

➜  ~ docker run -i -t ubuntu /bin/bash

docker run
run Run a command in a new container

docker run -i -t
-t Allocate a pseudo-TTY
-i Keep STDIN open even if not attached

➜  ~ docker ps

Docker starts an exited container

➜  ~ docker ps -a

➜  ~ docker container start cdaa2839dba6
cdaa2839dba6

Docker enters a running container

➜  ~ docker exec -i -t cdaa2839dba6 /bin/bash

Docker stop running container

➜  ~ docker stop cdaa2839dba6

Add a Comment

Your email address will not be published.