Docker mirror production details

  • 2020-05-17 07:11:02
  • OfStack

Recently, due to work reasons, we need to make Docker mirror, and it may be helpful for you to record here!

Write above: in this paper, the docker mirroring method is more suitable for one-time modification based on the existing docker mirroring.

It is recommended to use Docker File to make docker mirrors.

The principle is the same, but making an docker image with docker file allows you to record the steps so that you can change it later or recreate it if the image is lost.
In this paper, Ubuntu is used as the base image to pre-start 1 django project and ssh service and make a new image.

1. Basic mirror image

I used the ubuntu image downloaded from the Docker website.

docker run ubuntu

or

docker pull ubuntu

2. Install the ssh service

docker run-i-t ubuntu /bin/bash # create a container where -t is a temporary terminal.

After entering ubuntu, install openssh

apt-get install openssh-server # install ssh

# need to modify the contents of the file /etc/sshd/sshd_config

PermitRootLogin yes

UsePAM no

Modify ubuntu's root user password so that ssh can log in later:

sudo passwd root

3. Create a new mirror image

At this point, we need to submit this container with ssh service as an image, so as to facilitate various modifications on this basis in the future:

docker commit < container id > < image name >

4. Based on the Ubuntu image of the existing ssh service, join the django project and set it to start from the container

ok, after the above steps, doker images can be viewed, the newly submitted doker image is already inside, for example, image name is the new image of ssh-ubuntu.
The basic Ubuntu container is no longer functional
using

doker stop < container id >
doker rm < Container id >

Clear the most basic Ubuntu container that has just been started

Now, to personalize the image based on our new ssh-ubuntu, first, run the image

docker run -d -p 5001:22 ssh-ubuntu /usr/sbin/sshd -D

(-p is the port mapping container where port 22 should be within range of host 5001 port || /usr/sbin/ sshd-D is the command to run after the specified container is started. ssh service is started.)

After the container is started, we can log into the container via ssh

ssh root @doker0_ip-p 5001(22 mapped port)

Once inside the container, you are ready for the next step of customization. For example, I'm going to put my django project in the mirror and start it with the container.

(1) copy the django project into the container with the scp command.

(2) common startup process method:

Install supervisor!

apt-get update && apt-get install supervisor

(if apt-get install cannot find the package, update1 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 and exit.

Use the 3 section method to create a new image and clear the current container.

5. Run the new image

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

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

docker itself is index.docker.io uploaded by push, which is pulled by pull. However, there is no condition to set up a local docker warehouse or to export the application to another Docker environment. We can export the docker image to one file. The specific method is as follows:

sudo docker export < Container id > > docker_app.tar

Once that's done, the container we just created will be exported as docker_app.tar, which will then be imported when other machines are deployed

cat docker_app.tar | sudo docker import - docker_app

docker_app at the end of the pipe names image after the import and specifies it

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


Related articles: