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