Docker Hello World

Source: Internet
Author: User
Tags docker ps docker run

Example 1: Hello World


# Download a base image

Sudo docker pull Ubuntu or sudo docker pull busybox


# Execute a simple command

Sudo docker run Ubuntu/bin/ECHO Hello World

Explanation:
Run the root permission on sudo.
Docker run runs a new container
Ubuntu: The image for running commands internally
/Bin/echo the command we want to run internally
Hello word output content


# Use A Ubuntu image to create a container and run a simple hello World Process

Container_id = $ (SUDO docker run-D Ubuntu/bin/sh-c "While true; do echo Hello world; sleep 1; done ")

Sudo docker logs $ container_id

Explanation:

Run sudo docker run-D to run a new container. Run the-D command to run it as a process.
Ubuntu is an image that we want to run commands internally.
/Bin/sh-C is the command we want to run inside the container
While true; do echo Hello world; sleep 1; done is a simple script. We only print Hello word once a second until we finish it.
$ Container_id: A container ID is returned when you run the command.


# Check the log file to check whether it works properly

Sudo docker logs $ container_id

Docker logs returns the container log
$ Container_id the container ID we want to view


# View the result in real time after receiving the result from the container

Sudo docker attach-sig-proxy = false $ container_id

Docker attach allows us to view a background process.
-Sig-proxy = false: Container forwarding signal is not used. CTRL-C is allowed to exit.

 

# View running processes

Sudo docker PS

# Stop a container

Sudo docker stop $ container_id

Docker Hello World

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.