Latest web development tutorials

Docker Hello World

Docker allows you to run applications in the container, using the docker run command to run an application in the container.

Hello world output

w3big@w3big:~$ docker run ubuntu:15.10 /bin/echo "Hello world"
Hello world

Analytical parameters:

  • docker: Docker binary executable file.

  • run: previous docker combination to run a container.

  • ubuntu: 15.10 designated to run the mirror, Docker first from the local host mirror exists, if does not exist, Docker will be downloaded from a mirror image of public warehouse Docker Hub.

  • / bin / echo "Hello world" : in order to start the implementation of the container

The above command complete meaning can be interpreted as: Docker to create a new image ubuntu15.10 container, and then execute bin / echo "Hello world" in the container, and then outputs the result.


Running an interactive container

We docker two parameters -i -t, let container docker run to achieve "dialogue" capability

w3big@w3big:~$ docker run -i -t ubuntu:15.10 /bin/bash
root@dc0050c79503:/#

Analytical parameters:

  • -t: Specifies a pseudo-terminal or in the new container terminal.

  • -i: allows you to enter a standard container (STDIN) to interact.

At this point we have entered a ubuntu15.10 container system

We try to run in a container command cat / proc / version and ls respectively view the list of file version information systems and the current in the current directory

We can run the exit command or use CTRL + D to exit the container.


Starting container (background mode)

Create a process container run using the following command

w3big@w3big:~$ docker run -d ubuntu:15.10 /bin/sh -c "while true; do echo hello world; sleep 1; done"
2b1b7a428627c51ab8810d541d759f072b4fc75487eed05812646b8534a2fe63

In the output, we do not expect to see the "hello world", but a string of characters long

2b1b7a428627c51ab8810d541d759f072b4fc75487eed05812646b8534a2fe63

This is called the long string container ID, for each container, is unique, we can through the container ID to view the corresponding container what happened.

First, we need to make sure the container has run, you can view the docker ps

w3big@w3big:~$ docker ps

CONTAINER ID: Container ID

NAMES: container name automatically assigned

Use docker logs command in the container, the container to view the standard output

w3big@w3big:~$ docker logs 2b1b7a428627

w3big@w3big:~$ docker logs amazing_cori


Stop the container

We use docker stop command to stop the container:

By docker ps view, the container has stopped working:

w3big@w3big:~$ docker ps

You can also use the following command to stop:

w3big@w3big:~$ docker stop amazing_cori