Docker mirror production of detailed introduction _docker

Source: Internet
Author: User
Tags ssh scp command docker run

Recently because of work reason, need to Docker mirror to make, here record, perhaps to everybody also have certain help!

Written in front: This article Docker mirroring method is more suitable for one-time modification based on an existing Docker image.

It is recommended to make Docker mirrors with Docker file.

The principle is the same, but using Docker file to make Docker mirroring can record the operation steps to facilitate later changes or the loss of the mirror after the creation.
This article is based on Ubuntu mirroring, pre-start a Django project and SSH service to create a new mirror.

1, the basic image

I chose the Ubuntu image that I downloaded from Docker's official website.

Docker run Ubuntu

Or

Docker pull Ubuntu

2. Install SSH service

Docker run-i-T Ubuntu/bin/bash #创建一个容器,-T is a temporary terminal.

After entering Ubuntu, install OpenSSH

Apt-get Install Openssh-server #安装ssh

#需要修改 the contents of the/etc/sshd/sshd_config file

Permitrootlogin Yes

Usepam No

Modify Ubuntu root password for SSH login later:

sudo passwd root

3, create a new mirror

In this case, we need to submit this container with SSH service as a mirror, to facilitate later on the basis of the various modifications:

Docker commit <container id> <image name>

4, based on the existing SSH service Ubuntu image, join the Django Project, and set up with the container from the start

OK, after the steps above, doker images can see that the newly submitted Doker mirror is already in it, such as the new mirror image name Ssh-ubuntu.
The most basic Ubuntu container is no longer useful.
Use

Doker Stop <container id>
Doker RM <container Id>

Clear the most basic Ubuntu container that just started

Now, to personalize it based on our new Ssh-ubuntu, start by running the mirror

Docker run-d-P 5001:22 ssh-ubuntu/usr/sbin/sshd-d

(-P is the port mapping container 22 port should range host 5001 Port | | /usr/sbin/sshd-d is the command to run after the specified container starts, and this is to start the SSH service.

After the container is activated, we can log in to the container via SSH.

SSH root@doker0_ip-p 5001 (22 map port)

After entering the container, you can personalize the next step. For example, I'm going to put my Django project in the mirror and start with the container.

(1) Copy the Django item to the container and use the SCP command.

(2) Compare the general boot process method:

Install supervisor!

Apt-get Update && apt-get install Supervisor

(If Apt-get install can't find the package, update it first)

Then edit the configuration file, vi/etc/supervisord.conf

[Supervisord]
Nodaemon=true
[program:sshd]
command=/usr/sbin/sshd-d

[program:tomcat]
Command=python ~/ manager.py Runserver 0.0.0.0:9999

Then save the exit.

Use the 3 bar method to recreate the new mirror and clear the current container.

5, running the new mirror

Docker run-d-P 5001:22-p 5000:9999 <image-name>/etc/supervisord
At this point, you can access the host port 5000 to see if you can access the Django project inside the container.
The overall process of mirroring is complete.

*************************************************************************************************************** **************************************

Docker itself is a push to upload the Index.docker.io, the use is pull pull. But there are no conditions to build a local Docker warehouse or to export the application to another Docker environment, we can export the Docker image to a file, as follows:

sudo docker export < container id> > Docker_app.tar

When finished, the container we just made is exported to the Docker_app.tar file and will be imported later when other machines are deployed.

Cat Docker_app.tar | sudo docker Import-docker_app

The Docker_app behind the pipe is named after the import image, and you specify

Thank you for reading, I hope to help you, thank you for your support for this site!

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.