Dockerfile is a script composed of a series of commands and parameters, which are applied to the basic image and finally create a new image. They simplify the process from beginning to end and greatly simplify the deployment.
Create the dockerfile configuration file as follows
Source image used
FROM ubuntu #Container commands executed by run RUN apt -y update && apt -y upgrade && apt install -y vim \ nginx #Open port EXPOSE 80 #For the command executed after startup, add / bin / bash when executing the docker run... Command, and the CMD setting will be invalid #Running nginx in the foreground CMD ["nginx","g","daemon off;"]
- The run instruction is executed at image build time, and run is often used to install software packages.
- The CMD sets the command and its parameters that are executed by default after the container is started, but the CMD can be replaced by the command line parameters that follow docker run. When there are multiple CMD instructions, only the last CMD is valid
Perform the compile image operation in the directory where the dockerfile file is located.
docker build -t pfinal/nginx .
Check whether the image compilation is successful
Modify / etc / hosts to add the resolution record of pfinal.org local domain name
... 127.0.0.1 pfinal.org ...
docker run -tid -p 8080:80 -v /www:/var/www/html --name nginx pfinal/nginx
The host uses http://pfinal.org or localhost: 8080 (if the host does not use 80, you can map 80 ports) to access nginx
The created image can be uploaded to the Internet for use by others.
Log in to docker hub
Push image to warehouse
docker push pfinal/lamp
Log in to https://hub.docker.com/ to view the images submitted by the rigid in the repositories.
Now other users can use the following command to install our image.
docker pull pfinal/lamp
Exit docker hub
Docker compose is a tool for docker containers to choreograph, define and run multi container applications, and start multiple containers with one command.
We will talk about using composer to configure containers in a separate chapter later.
Download and install
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Add execution permission
sudo chmod +x /usr/local/bin/docker-compose
View installed version
delete a window
docker-compose rm laradock_redis_1
Pull mirror image
docker-compose pull nginx
Services for the lifting project
OK, that’s it!