Hello world for getting started with Docker

It is said that the first program written by a programmer is to output hello world. I installed docker in contos7 two days ago. Today I will output a hello world to get started.

Docker allows to use docker run to run applications inside the container, and we can use docker run to output hello world.

1. Check whether docker is installed correctly.

docker info     //如果安装正确就会有很多docker的信息,如下图:

docker-info

If you install and execute docker info correctly, it will output a lot of information as shown in the figure, and my picture is not cut off.

2. Output hello world.

 docker run busybox /bin/echo hello world 

 

Semantic description of each parameter:

docker: Docker binary executable file.

run: combined with docker to form a command to run the container.

Busybox: Busybox is called the Swiss Army Knife of Embedded Linux. Busybox integrates many small common functions under Unix into a small executable file, which is a castrated version of Linux system.

/bin/echo hello world: This is the command that runs in the container.

3. Output hello world in background mode.

docker run -d busybox /bin/sh -c "while true; do echo hello world; sleep 1; done"

This sentence means that hello world will always be output in the container. But you will see a string after execution.

 

This string is the ID of the container and is unique. If we want to see the log, let's see if our container is running.

docker ps

 

We can see the container we are running. The meaning of each parameter is as follows:

CONTAINER ID: Container ID.

IMAGE: The image used.

COMMAND: The command to run when the container is started.

CREATED: The creation time of the container.

STATUS: Container status. There are 7 types: created (created), restarting (restarting), running (running), removing (migrating), paused (suspended), exited (stopped), dead (dead).

PORTS: The port information of the container and the connection type used (tcp\udp).

NAMES: automatically assigned container names.

Fourth, use the docker logs command to view the output in the container.

//使用容器id
docker logs feeb6f3ef1a3

 

//使用容器name
docker logs  pedantic_thompson

 

5. Stop the container.

docker stop feeb6f3ef1a3

 

再次通过名称查看运行的容器
docker ps

 

Found that there are no running containers. Of course, you can also use the container name to stop

docker stop pedantic_thompson

The docker output hello world is over, have you learned?

Guess you like

Origin blog.csdn.net/wzs535131/article/details/108188599