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 \
#Open port
#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

Compilation mirroring

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

docker images

Mirror image

Modify / etc / hosts to add the resolution record of local domain name


Running container

docker run -tid -p 8080:80 -v /www:/var/www/html --name nginx pfinal/nginx

The host uses or localhost: 8080 (if the host does not use 80, you can map 80 ports) to access nginx

Mirror upload

The created image can be uploaded to the Internet for use by others.

Log in to docker hub

docker login
Push image to warehouse
docker push pfinal/lamp

Log in to 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 logout

Docker Compose

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 "$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Add execution permission

sudo chmod +x /usr/local/bin/docker-compose

View installed version

docker-compose --version


View container

docker-compose ps

delete a window

docker-compose rm laradock_redis_1

Pull mirror image

docker-compose pull nginx

Services for the lifting project

docker-compose restart

OK, that’s it!