Docker Book: Difference between revisions

From Rixort Wiki
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
Notes for upcoming book on Docker
Notes for upcoming book on Docker and PHP.


== Installing Docker ==
== Installing Docker ==
Line 5: Line 5:
* Point to instructions on Docker website, no point in duplicating these
* Point to instructions on Docker website, no point in duplicating these
* Make sure you are running the latest version
* Make sure you are running the latest version
* Use upstream repositories as the distribution ones are too out of date
* If running Ubuntu, use LTS as the host


== Hello World ==
== Hello World ==
Line 14: Line 16:
== Basic PHP example ==
== Basic PHP example ==


* <code>docker run --rm php:7.4-apache-buster</code>
* <code>docker run --rm php:7.4-apache-buster php -v</code>, show output
* <code>docker run --rm php:7.4-apache-buster php -v</code>, show output


Line 29: Line 30:
* <code>docker run --rm -p 8000:80 phpinfo</code>
* <code>docker run --rm -p 8000:80 phpinfo</code>
* Visit localhost:8000 in browser
* Visit localhost:8000 in browser
* Ctrl+C terminates container and Docker will remove it automatically due to the <code>--rm</code> flag
== Docker Compose ==
Docker Composer (<code>docker-compose</code>) is a way to configure Docker with YAML. For example, you can specify environment variables in a YAML list, instead of having to supply them all on the command line. It also makes life much easier if you want to run multiple containers together, e.g. web and database containers.
If you are adding Docker to a project for the first time, you should use Docker Compose by default.
== Dependencies ==
If you have multiple containers, it is likely that there will be dependencies between them. For example, the container hosting your web application most likely depends on the database container - until the database container has been started, the application is not 'ready'.
Dependencies can be expressed with the <code>depends_on</code> attribute.
[[Category:Docker]]

Latest revision as of 08:55, 20 August 2021

Notes for upcoming book on Docker and PHP.

Installing Docker

  • Point to instructions on Docker website, no point in duplicating these
  • Make sure you are running the latest version
  • Use upstream repositories as the distribution ones are too out of date
  • If running Ubuntu, use LTS as the host

Hello World

  • docker run --rm hello-world
  • Include example output for checking
  • Explain use of --rm flag - without this we end up with lots of stopped but not removed images

Basic PHP example

  • docker run --rm php:7.4-apache-buster php -v, show output

Dockerfile:

 FROM php:7.4-apache-buster
 COPY index.php /var/www/html/index.php

index.php:

 <?php phpinfo();
  • docker build -t phpinfo:latest .
  • docker run --rm -p 8000:80 phpinfo
  • Visit localhost:8000 in browser
  • Ctrl+C terminates container and Docker will remove it automatically due to the --rm flag

Docker Compose

Docker Composer (docker-compose) is a way to configure Docker with YAML. For example, you can specify environment variables in a YAML list, instead of having to supply them all on the command line. It also makes life much easier if you want to run multiple containers together, e.g. web and database containers.

If you are adding Docker to a project for the first time, you should use Docker Compose by default.

Dependencies

If you have multiple containers, it is likely that there will be dependencies between them. For example, the container hosting your web application most likely depends on the database container - until the database container has been started, the application is not 'ready'.

Dependencies can be expressed with the depends_on attribute.