Dockerfile
After figuring out what docker is going on, of course we need to make several images of our own. There are two ways to create an image:
First, download an official image, run something you need in it, and then commit it into an image.
Another method is to use Dockerfile.
But in essence, the two methods are the same-because the content of Dockerfile is just a bunch of RUN commands ......
The file name of Dockerfile is generally called Dockerfile, which is convenient because it can be directly used to generate an image:
docker build -t yourname/imagename:yourtagname .
If the file name is not used, use the following command:
docker build -t yourname/imagename:yourtagname - < yourdockerfilename
Yourtagname can be omitted. The default value is latest. After the build is complete, a new image is generated based on the Dockerfile content. The image name is yourname/imagename.
The most basic content of Dockerfile is the FROM Command and the RUN Command.
FROM is used to specify which image is used as the basis, and RUN is to create a new iner on the basic image and RUN the command. A simple example is as follows:
FROM ubuntuRUN echo "deb http://cn.archive.ubuntu.com/ubuntu precise main" > /etc/apt/sources.listRUN apt-get updateRUN apt-get install -y vim
Other optional and advanced Commands include MAINTAINER, ENTRYPOINT, USER, and EXPOSE. Simple Description:
MAINTAINER: MAINTAINER description
ENTRYPOINT: As the startup program when the container is running
USER: the identity used by the startup program when the container is running.
EXPOSE: port number to be listened to when the container is running
For more information, see the official documentation.
Note that when using docker build to create an image, each run statement in Dockerfile is run sequentially, and each run statement generates a separate container.
Share an image
Self-built images can be uploaded to the official repository and shared with you for future reuse.
Before uploading, you must register a user in the official repository. Note: after registration, you must first receive the email. You can log on from docker only after you have verified the email address.
Then log on to the official repository from the local docker:
docker login
Then you can upload your own image:
docker push yourname/imagename
Docker-registry
It is not convenient to use the official Warehouse through the wall, and there will always be something that is not convenient to be put in the official Warehouse for public, so it is necessary to build a self-built warehouse.
My repository is built on a FreeBSD server. follow these steps:
The first step is to install git. To be honest, I do not like git very much. It is far from simple and convenient to use hg. In addition, after installing it with ports on FreeBSD just now, an error occurred while running. When cloning, core dump. Finally, openssl and curl are upgraded.
Step 2: clone the docker-registry Code:
git clone https://github.com/dotcloud/docker-registry.git
Step 3 is to prepare the running environment of docker-registry. Because it is written in python, I opened a virtualenv for it. However, because gevent is used, installing gevent in FreeBSD's virtualenv may be a little troublesome. For details, see my previous articles. Therefore, you must first install gevent, and then install a libevent.
Cd/usr/ports/devel/libevent # Note: Do not clean, to compile gevent, you also need to use make install # Use the virtualenvwrapper command to enter the specified virtualenv environment workon your_virtualenv # download gevent without installing pip install -- no-install gevent = 0.13.8 # enter the downloaded gevent location cdvirtualenv build/gevent # libevent refer to your actual environment python setup. py install -- libevent/usr/ports/devel/libevent/work/libevent-1.4.14b-stablepip install gevent # Go Back To The docker-registry location cd path_to/docker-registrypip install-r requirements.txt
However, all of the above are for FreeBSD. If it is for ubuntu, it will be much simpler. apt installation is complete. For details, see the official documentation.
The third step is configuration. The simplest way is to use the default configuration. For more details, see the official documentation. The default configuration method is as follows:
cd configcp config_sample.yml config.yml
Step 4: run:
gunicorn --access-logfile - --debug -k gevent -b 0.0.0.0:5000 -w 1 wsgi:application
Note: The above default configurations and running commands work in test/debug mode. Modify the configurations and commands for actual applications.
If necessary, you can add Apache/Nginx as a proxy and publish it to the Internet to share with your friends. This will not be repeated.
Use of docker-registry
How to use self-built docker-registry?
The first thing to do is:
Stop the docker daemon with the proxy and restart the default service:
ps aux | grep "sudo docker"sudo kill [docker-daemon-pid]sudo service docker start
Because the self-built registry obviously does not need a proxy, adding a proxy will fail to connect.
Then look at the ID of the local image and select one to upload:
docker images | grep ubuntu | grep latest
Then set its repository Name:
docker tag [image_id] [your-registry-host]:5000/ubuntu
OK. Now you can push:
docker push [your-registry-host]:5000/ubuntu
Then you can download it from the registry on another machine:
docker pull [your-registry-host]:5000/ubuntu
That's it.