Building and using Docker for development

Most important docker docs section

Build docker

cd docker dir

docker build --tag="NAME" .

Example:

docker build --tag="web" .

docker build --tag="postgres" .

docker build --tag="redis" .

  • The tag is to help you differentiate what docker does what

When all three dockers are built with proper tags

Here we get to the docker run section. This starts a docker from an image we built. We can start many different dockers from the same image but each started docker becomes unique.

The option -d for the run command is to deamonize the docker. You can use other options like -i (interactive) and -t (tty) to be able to open an interactive shell for the docker. Look at the docs for more information.

In the commands below you can see a path being used by the option -v (The -v option stands for volume and is for mounting directories inside the dockers). We need to substitute this to fit our own filesystem. The colon after the filesystem path is the target. That is the filesystem path inside the docker that we want to link our own path to.

We also do an internal to external portforwarding so we can access our internal docker network from the outside. The userguide talks about this if more information is needed.

name="" in the code examples below will be the name the started docker process will be referenced by. This is important as to how you link dockers together. If you don not us the names suggested by me the automatic configurations script will not work.

docker run --name="redis" -d redis

docker run -d --name="postgres-1" postgres

docker run -d -h docker --link redis:redis --link postgres-1:postgres-1 --name="web" -v /home/user/mrf-kalkyl:/var/www/mrf-kalkyl -P web

Remember to change the filepath for -v to fit your system. Change the /home/user/mrf-kalkyl part.

When all docker are started

If all docker are run and you can seem them alive with docker ps we need to do the final step to setup the deploy for docker. Also make sure all portforwarding looks right. docker ps will tell your what ports are forwarded.

First migrate the databse docker exec web sh -c "(cd /var/www/mrf-kalkyl && yes | php artisan migrate)"

If you want test data, run seeding docker exec web sh -c "(cd /var/www/mrf-kalkyl && yes | php artisan db:seed)"

And finally, run the deploy script: docker exec web sh -c "(cd /var/www/mrf-kalkyl/scripts && ./set_config.sh -wd)"

  • -w in the context of the deploy script means “Whale” and is meant to pick Docker as the destination for the deploy.
  • -d means setup and seed the database.

run ./set_config without options to see all options. If the config is not run the web docker will not know how to reach the Redis and Postgres dockers.

Up and running

Access the application at https://0.0.0.0:49153 You can se port with docker ps, 0.0.0.0:49153->443/tcp

Troubleshooting

  • Permissions error at /storage? chmod -R 775 app/storage/
  • To stop and delete all containers docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)