Copyright, without permission, is prohibited reprint
chapter
- Docker Introduction
- Docker and the difference between virtual machines
- Docker installation
- Docker Hub
- Docker mirror (image)
- Docker container (Container)
- Docker container operations
- Docker container shell
- Docker Dockerfile
- Construction Docker mirror (docker build)
- Docker Dockerfile instruction
- Docker examples
- Docker Compose
- Docker network
docker can execute any application. In this chapter we will create a Php application, and run it using the docker.
1. Create a project directory
We will file related to this project, into a centralized directory docker-php
:
[root@qikegu demo]# mkdir docker-php
2. Create a PHP file
In the docker-php
directory, create a php file:
qikegu.php
<?php
echo "This is php app - qikegu.com"
?>
3. Create Dockerfile
After you create Php file, we need to create a Dockerfile, which contains Docker's instructions. In the docker-php
creation Dockerfile directory, file name must be Dockerfile
.
Dockerfile
FROM php:7.3
COPY . /var/www/php
WORKDIR /var/www/php
CMD ["php", "./qikegu.php"]
All commands are capitalized, as is customary.
Now docker-php
there are two files in the directory:
[root@qikegu docker-php]# ls
Dockerfile qikegu.php
4. Construction of the mirror Docker
Switch to the docker-php
directory, run docker build -t qikegu-php .
commands, build Docker mirror. Docker image can be named, here named qikegu-php
.
docker build -t qikegu-php .
Sending build context to Docker daemon 3.072kB
Step 1/4 : FROM php:7.3
7.3: Pulling from library/php
743f2d6c1f65: Already exists
6307e89982cc: Already exists
807218e72ce2: Already exists
5108df1d03f8: Already exists
6379b2ee8208: Pull complete
97904243782e: Pull complete
6f3a7ed1fc19: Pull complete
e4924fe2ab64: Pull complete
57a3ef7493d5: Pull complete
Digest: sha256:00f053cdb2e46bab5d9ea20c416a007aa84b15883b22a9073a83e1d2f96f0b55
Status: Downloaded newer image for php:7.3
---> e1dce93645bd
Step 2/4 : COPY . /var/www/php
---> d5c47dfa4f38
Step 3/4 : WORKDIR /var/www/php
---> Running in b6f81d4db002
Removing intermediate container b6f81d4db002
---> 996e3419c48f
Step 4/4 : CMD ["php -f", "qikegu.php"]
---> Running in 52957ffeebd4
Removing intermediate container 52957ffeebd4
---> df09b84b2033
Successfully built df09b84b2033
Successfully tagged qikegu-php:latest
[root@qikegu docker-php]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
qikegu-php latest 25c6fdde4da0 4 minutes ago 367MB
...
Here, last used docker images
to view mirror, the mirror can be seen to build success. Then you can run the mirror.
5. Run Docker mirror
Execute docker run qikegu-php
command run-time image:
[root@qikegu docker-php]# docker run qikegu-php
This is php app - qikegu.com
[root@qikegu docker-php]#
We can see, qikegu-php
mirroring the successful operation, the output of a message.