This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docker:build_create_run_image_phpinfo [2020/03/05 16:05] admin |
docker:build_create_run_image_phpinfo [2020/03/05 16:20] (current) admin |
||
---|---|---|---|
Line 108: | Line 108: | ||
<code bash> | <code bash> | ||
+ | #Donwloading and creating docker image from GitHub called php:7-apache | ||
FROM php:7-apache | FROM php:7-apache | ||
+ | |||
+ | #Your email and information | ||
MAINTAINER YOUR_EMAIL_OR_ORGANIZATION | MAINTAINER YOUR_EMAIL_OR_ORGANIZATION | ||
+ | #Copy local created file 000-default.conf to image-php-server right location | ||
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf | COPY 000-default.conf /etc/apache2/sites-available/000-default.conf | ||
+ | |||
+ | #Copy start-apache script to executible linux directory | ||
COPY start-apache /usr/local/bin | COPY start-apache /usr/local/bin | ||
+ | |||
+ | #Laravel requires Apache’s mod_rewrite plugin to be enabled, we can do this using the a2enmod utility. With RUN, we run commands inside the container | ||
RUN a2enmod rewrite | RUN a2enmod rewrite | ||
- | # Copy application source | + | # Copy application source and permissions for source folder |
- | COPY src /var/www/ | + | COPY index.php /var/www/public/ |
RUN chown -R www-data:www-data /var/www | RUN chown -R www-data:www-data /var/www | ||
CMD ["start-apache"] | CMD ["start-apache"] | ||
</code> | </code> | ||
+ | Our folder contains a Dockerfile, a 000-default.conf and start-apache. The docker build command will build the Dockerfile inside the current directory: | ||
+ | <code bash> | ||
+ | [root@localhost v1]# docker build -t php-7-apache:v1 . | ||
+ | Sending build context to Docker daemon 6.144kB | ||
+ | Step 1/8 : FROM php:7-apache | ||
+ | 7-apache: Pulling from library/php | ||
+ | 68ced04f60ab: Pull complete | ||
+ | 1d2a5d8fa585: Pull complete | ||
+ | 5d59ec4ae241: Pull complete | ||
+ | d42331ef4d44: Pull complete | ||
+ | 408b7b7ee112: Pull complete | ||
+ | 570cd47896d5: Pull complete | ||
+ | 2419413b2a16: Pull complete | ||
+ | 2c7832852643: Pull complete | ||
+ | 8b0b209a25bc: Pull complete | ||
+ | 46011418685f: Pull complete | ||
+ | 68be3748ea55: Pull complete | ||
+ | 4e3af655ec1e: Pull complete | ||
+ | 9f579d3b7159: Pull complete | ||
+ | Digest: sha256:c496c0f962eaaea0f52d9c068bf331fe477703d4657f99b955a2a35a4c3486c4 | ||
+ | Status: Downloaded newer image for php:7-apache | ||
+ | ---> d753d5b380a1 | ||
+ | Step 2/8 : MAINTAINER YOUR_EMAIL_OR_ORGANIZATION | ||
+ | ---> Running in 39e672a90b5a | ||
+ | Removing intermediate container 39e672a90b5a | ||
+ | ---> 4d25a2d00117 | ||
+ | Step 3/8 : COPY 000-default.conf /etc/apache2/sites-available/000-default.conf | ||
+ | ---> 19a2cdc56a9f | ||
+ | Step 4/8 : COPY start-apache /usr/local/bin | ||
+ | ---> 603ec78bbed1 | ||
+ | Step 5/8 : RUN a2enmod rewrite | ||
+ | ---> Running in a7fff2718075 | ||
+ | Enabling module rewrite. | ||
+ | To activate the new configuration, you need to run: | ||
+ | service apache2 restart | ||
+ | Removing intermediate container a7fff2718075 | ||
+ | ---> 9bdfd2fefddd | ||
+ | Step 6/8 : COPY index.php /var/www/public/ | ||
+ | ---> 1c116f043a28 | ||
+ | Step 7/8 : RUN chown -R www-data:www-data /var/www | ||
+ | ---> Running in 84452265396e | ||
+ | Removing intermediate container 84452265396e | ||
+ | ---> d059277e4af0 | ||
+ | Step 8/8 : CMD ["start-apache"] | ||
+ | ---> Running in a82d06ffb356 | ||
+ | Removing intermediate container a82d06ffb356 | ||
+ | ---> 6f4b2f7f4ec3 | ||
+ | Successfully built 6f4b2f7f4ec3 | ||
+ | Successfully tagged php-7-apache:v1 | ||
+ | </code> | ||
+ | If we list our Docker images now, we’ll see our new built image: | ||
+ | <code bash> | ||
+ | [root@localhost v1]# docker images | ||
+ | REPOSITORY TAG IMAGE ID CREATED SIZE | ||
+ | php-7-apache v1 6f4b2f7f4ec3 2 hours ago 414MB | ||
+ | </code> | ||
+ | |||
+ | Finally run a container on port 80: | ||
+ | |||
+ | <code bash> | ||
+ | [root@localhost v1]# docker run -d -p 80:80 php-7-apache:v1 | ||
+ | 051f5da1a58e483ff672ef32b7a6124a809893b31a3caa27c907a100e8d935e9 | ||
+ | </code> | ||
+ | |||
+ | Check is container running: | ||
+ | <code bash> | ||
+ | [root@localhost v1]# docker ps -a | ||
+ | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES | ||
+ | 051f5da1a58e php-7-apache:v1 "docker-php-entrypoi…" 2 hours ago Up 2 hours 0.0.0.0:80->80/tcp jovial_vaughan | ||
+ | </code> | ||
+ | Result : | ||
+ | {{ :linux:docker_phpinfo_v1.png |}} | ||
+ | |||