Package a Docker image so that your friends can load and open a container and output hello and world to the specified file every second,

Source: Internet
Author: User

Package a Docker image so that your friends can load and open a container and output hello and world to the specified file every second,

I. Two script codes

Dockerfile

1 FROM bash2 COPY . /usr/herui/3 WORKDIR /usr/herui/4 CMD [ "sh", "hello_world.sh" ]

Hello_world.sh

1 #!/bin/bash2 while true3 do4 echo 'hello world!' >> /usr/herui/hello_world.log5 sleep 16 done

 

Ii. package it into an image

1,

 1 [root@localhost herui]# docker build -t hello_world:1.01 2 "docker build" requires exactly 1 argument(s). 3 See 'docker build --help'. 4  5 Usage:  docker build [OPTIONS] PATH | URL | - 6  7 Build an image from a Dockerfile 8 [root@localhost herui]# docker build -t hello_world:1.01 . 9 Sending build context to Docker daemon  3.072kB10 Step 1/4 : FROM bash11  ---> 906f4bf24f0012 Step 2/4 : COPY . /usr/herui/13  ---> Using cache14  ---> ab38183c9bcb15 Step 3/4 : WORKDIR /usr/herui/16  ---> Using cache17  ---> 24442df0587c18 Step 4/4 : CMD sh hello_world.sh19  ---> Using cache20  ---> 9413de166e6f21 Successfully built 9413de166e6f22 Successfully tagged hello_world:1.01

Note that the packaging command must be executed under Dockerfile and hello_world.sh, And the last "." command is followed by the context path.

2. Check the image file list to see if it is successful.

1 [root@localhost herui]# docker images2 REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE3 hello_world         1.01                9413de166e6f        2 days ago          12.1MB

 

Save the three directories in the tar.gz format and check whether the packages in the current directory exist.

1 [root@localhost herui# docker save hello_world:1.01 | gzip > hello_world.tar.gz2 [root@localhost herui]# ls -lh hello_*3 -rw-r--r--. 1 root root   92 Aug 31 17:53 hello_world.sh4 -rw-r--r--. 1 root root 4.4M Sep  3 01:29 hello_world.tar.gz

 

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.