Two image creation of Docker learning

Source: Internet
Author: User
Tags docker ps

Write a little bit of experience after getting started with Docker.

by command: docker run-it repository or image ID Note: fields followed by-it can be obtained with the following command

Creating a running container will enter a pseudo terminal, and if you use ctrl+d or use the exist command to exit the pseudo-terminal, it will cause the container to also terminate. Correct introduction of pseudo-terminal posture is:ctrl+p and then press ctrl+q so that the pseudo-terminal and the container can be separated.

Ps: So far you can find some commands on your own, using Docker--help to see some commands. Where the attach function can be implemented to re-login to the container, just this time attach followed by the container ID, remember that the ID of the container is occasionally mirrored id,docker PS command can be obtained . Attach command input after the carriage return will stop, you need to enter again to enter the pseudo terminal.

To create a mirror:

Creating an image with the analogy on the Windows platform is equivalent to having a system (such as Win7) in the virtual machine, and then loading your own apps or software into the system, and then you don't have to reinstall the system on another machine, just clone the virtual machine to another machine.

There are two ways to create a mirror, one is to use the Docker commit command to create a new image based on the image in the public repository, which is not suitable for the image that a team is using and configuring Another method is to use the configuration file in a way that is officially called Dockerfile, and the command to match it is the Docker build.

The second method is described in detail next

1.CD ~ go back to your user directory (this is because the official tutorial says that if you are using Docker in a Windows system, you need a cd to /c/user/your_user_name directory, so so on,Linux i CD ~ a bit)

2. Create a folder and create a Dockerfile under the folder

mkdir FileName

CD FileName

Touch Dockerfile

3. in Dockerfile , enter the following:

# Implementation Note # must be the first line to indicate the underlying image, which is used ubuntufrom ubuntu:14.04<[email protected]> the command run apt -get update && apt-get install-y Ruby ruby-devrun gem install Sinatra

 

This is a very simple dockerfile, in general, thedockerfile includes four parts of information: Basic image information (required), creator information (optional), instructions for mirroring operations (add as needed), and instructions to execute when the container starts (add as needed).

The format of the instruction is: instruction Execution Task (original: instruction statement)

Run this command allows the task commands to run in the mirror, the previous from,maintainer are commands, in addition to these three:

Add <src> <targetDirectory> This directive allows you to add local file copies to the container. <src> can be a relative path (file or directory) in the directory where the Dockerfile is located ,;<targetdirectory> is the path in the container and will be created. Another command is copy , format and Add, the implementation of copying native files into the container, we recommend the use of copy.

Expose (exposed container port number) command format is: Expose <PORT> [<port> <port> ...]

For example: EXPOSE 8081 22 23 exposing these ports can be used by interconnected systems, such as what you want to do with virtual Hadoop clusters, memory db clusters, etc.

Other command cmd (can run. sh file),env (Specify environment variable), Entrypoint,volume,user (specifies the user name of the container runtime), Workdir,onbuild is not introduced.

4.dockerfile Create A new image using Docker build after the creation is complete

Docker build-t Ouruser/sinatra:v2.

Note that the last point of the command, this is needed, represents our Dockerfile in the current folder. - T specifies that Ouruser owns this new image,Sinatra specifies the image name, andv2 is the version number

5. Create a new container to run from the image we created ourselves

Docker Run-t-I Ouruser/sinatra:v2/bin/bash

Ps: Create a mirror this part of my basic translation of the official website of the tutorial, but also supplemented the other information. When you create a local image based on Ubuntu or CentOS systems, you can first pull a system from the public repository with Docker pull, the time of the mirror is based on your network resources, it may be very long, I have been pulling for a long time, the middle or failed several times. This article to create a mirrored part of the no instance is because the Ubuntu image did not pull down, I just translated the official website of the tutorial, I feel that there should be no problem, the follow-up time to fill the picture. These two articles deal with simple applications probably can be dealt with, there may be some instructions or something I did not detail, but you can only use Docker--help to see what commands, in the use of Docker subcommand--help You can see what parameters can be set for the command.

Two image creation of Docker learning

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.