Some docker image test
This is useful if something is compiled. The compiler can run then stop and the compiled file can be used in your main container.
One container is used as a base image and one container that builds its image from that.
- Splitting a dockerfile into multiple stages can be useful. In the example if we make changes to the main containers dockerfile, we just rebuild the main container i.e. only follow the steps in that dockerfile to the base image. This can save alot of time if the base image has alot of steps.
- This can also be useful for having both development and poduction containers, created from a base web server image.
This is similar to extend-a-local-base-image. But when its built using docker-compose it will always build all the stages in the Dockerfile, until it gets to the last stage required. It multiple stages in one file but this may contain unwanted stages and is often wasteful in my opinion. But it can be useful if the container has two or more states without much difference, or that extend others. Like the exmaple here. In which case the order the stages are in the file should be considered.
Our container | dependancies | built stages in our example |
---|---|---|
base | base | |
prod | base | base,prod |
stage | base | base,prod,stage |
dev | prod,base | base,prod,stage,dev |
Here the order is based on limiting server build time and taking the penalty on dev setup time. This could be reduced by using a seperate Dockerfile for the dev stage and a seperate docker-compose.yml file for development environment to allow it to be used safly and reliably.
This is a simple php, apache, mysql container that uses a ubuntu container.
This shows how to use an nginx-proxy docker container to allow multiple sites to run, each with site with a seperate web server docker container e.g. nginx or apache
This shows how to use docker compose to run multiple versions of php symltaniously while using the same mysql container. This can be useful for testing a site on multiple versions of php or running multiple sites that require different php versions on your local.
This is a php, apache, mysql setup that uses an official php apache container
sudo docker run -p 8080:80 -d -v ~/Documents/Repositories/sites:/var/www/Website --name <> <>
-p 8080:80
-v ~/Documents/Repositories/sites:/var/www/Website
sudo docker exec -it <> bash Some containers have a different setup. These are some other options if that one dosen't work. sudo docker exec -it <> /bin/bash sudo docker exec -it <> sh sudo docker exec -it <> /bin/sh
This is useful to have a look around a container that dose a job and exits.
docker run -it compiler bash
- Commit the stopped container into an image docker commit <> debug/<>
- create a new container from the "broken" image docker run -it --rm --entrypoint sh debug/<>
- delete the container and the image docker image rm debug/<>
Warning: This will stop all your containers. docker stop $(docker ps -a -q)
Warning: This will destroy all your images and containers. It will not be possible to restore them! docker rm $(docker ps -a -q)
Warning: This will destroy all your images and containers. It will not be possible to restore them! docker rmi $(docker images -q)
This will create a container and start it. This will only build a container if it dosen't exist. docker-compose up
To rebuild this image you must use docker-compose build
. To stop docker using the cache add the --no-cache
flag 'e.g. docker-compose build --no-cache
docker-compose build <<container name>>
mysql -h<> --port=9906 -udevuser -p
or
mysql -h<
> --port=9906 -uroot -p
You cannot run mysql from inside another container but can connect to mysql from inside another container. The name of the container is used for the url. The other details are host: db; user: devpass password: devtest port: 3306
test the connection php /code/test_mysql_connection.php
Included are some test files to test that php, apache and mysql connections work. The list of tests are accessable from. The port can be found in the docker-compose.yml for the example. http://localhost:<>/docker-tests/
e.g http://localhost:8000/docker-tests/
my-web-php7.0:/code .
php & apache (my-web-php7.0): php 7.0 apache 5.7
mysql: mysql 5.7
http://:8080
https://docs.docker.com/compose/production/
based on: https://medium.com/@meeramarygeorge/create-php-mysql-apache-development-environment-using-docker-in-windows-9beeba6985 https://stackoverflow.com/questions/29480099/docker-compose-vs-dockerfile-which-is-better