Docker: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

This error has had a lot of people stumped by the looks of their issues on GitHub. I think the error stems from downloading Docker through their main landing page. I tried a lot to fix the issue and with no luck. This included switching the DNS over to 8.8.8.8 which has been suggested in the past and worked.

My answer to the issue is don’t use the main landing page to install Docker. Instead, you want to download it from here and then everything should work as normal.

If you have any questions, or feel it hasn’t worked for you, then please let me know.

Enjoy reading this blog? Please consider subscribing using the form below.

windows programming

Windows version of Linux’s $(pwd)

Tonight I was playing around with Docker in Windows and I wanted to use Node to install my packages to my local environment. Then I found a command on Chris Fidao’s Laravel Vessel website which looked like…

docker run --rm -it -v $(pwd):/opt -w /opt shippingdocker/php-composer:latest composer create-project laravel/laravel my-app

I modified it for use with npm to…

docker run --rm -it -v $(pwd):/opt -w /opt michaelbrooks/node:latest npm i vuepress

I ran the command and got the following…

docker: Error response from daemon: create $(pwd): "$(pwd)" includes invalid characters for a local volume name, only 
"[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intended to pass a host directory, use absolute path. See 'docker run
--help'.

A quick search and I found I could replace $(pwd) with %cd% which looked exactly like this…

docker run --rm -it -v %cd%:/opt -w /opt michaelbrooks/node npm i vuepress

Enjoy reading this blog? Please consider subscribing using the form below.

Docker has been fun, but it’s time to move on…

As a few of you may know, I have been using Docker for some time to deploy my site with. It’s been a great learning experience for me and is something I wish to carry on with.

However, because of the nature of the beast, and the lack of knowledge I have with the technology, I have decided that I shouldn’t be using it to host my live Blog when I am still learning how it works.

Therefore, I have decided to create a new DO Droplet and deploy my site with Laravel Forge. This is a cheap, but great solution which allows for unlimited servers and domains, and allows me to create a deployment strategy using many cloud services/servers.

As I am already using Digital Ocean, I thought it would make sense to carry on using this as it is just such a great service.

What the future holds

I do hope to carry on with Docker, but as I am still learning what it’s capable of, I will carry on using it locally. There are many things I am still finding out such as making your website code a data container, which is something I didn’t know at the time and could have been one of the reasons why my site was very volatile.

Every time I tried to update my CMS (which is running OctoberCMS), it would break something. This could have been due to my lack of knowing, or it could have been down to file permissions, or maybe using the wrong OctoberCMSversion.

Whatever it was, it now works a lot better being on a server management/deployment strategy and it should continue to keep working as long as I use the service. There are also plenty of great tutorials on how to use the service and it has a lot of great tools to help ease the stress of server management.

Like I say, I should never have used it on my live site before fully knowing, but I will continue to explore it’s uses and find easier ways of deployment. This is definitely not the end of my Docker usage, and I hope to have many more great experiences using such awesome technology.

How to containerize your PHP/NGINX docker project properly

This evening, I had myself a little challenge. I would turn my two containers (MariaDB and my own built container) into more containers. But using the power of Docker’s official container repos. E.g. I would have 3 containers in total PHP7-FPM, NGINX and my already created MariaDB.

If you don’t know my steps I previously created, you can check it out here. You can skip to MariaDB for your database container and settings.

Dockerfile

First off, I used the PHP container and followed instructions to have a PHP7-FPM container. You can see below for the Docker file, just copy it and run the command below…

docker build -t php7 . docker run -d --name php7 php7

This will build a php7 Image based on the PHP7-FPM container and add the relevant system, PHP and PECL extensions needed. Please bear in mind that this is for my OctoberCMS app and you may need different extensions. If this is the case, you will need to research and find the correct extensions for your project.

Now we have PHP7-FPM, we also need our trusty old proxy server NGINX.

docker run -p 80:80 -p 443:443 --name nginx -v "$PWD":/PATH/TO/PROJECT:ro -d nginx

To follow the next steps, we will need to temporarily stop our nginx server and start it up again once we’re finished…

docker stop nginx

NGINX Configuration

This will create our NGINX container using the ports usual ports including 443 for our secure port and share our project to the container as read-only (:ro).

Now for our SSL certificates. Run the following code and follow the steps which pop up.

sudo docker run -it --rm -p 443:443 -p 80:80 --name letsencrypt -v "/etc/letsencrypt:/etc/letsencrypt" -v "/var/lib/letsencrypt:/var/lib/letsencrypt" quay.io/letsencrypt/letsencrypt:latest auth docker start nginx

If you have followed along so far, then we have almost finished, we now need to copy our SSL directory to NGINX which will share the SSL directory as read-only.

docker cp /etc/letsencrypt/live/DOMAINNAME/nginx:/etc/letsencrypt/live/DOMAINNAME:ro

Finally, we can create a default.conf file and copy it into the correct nginx directory.

From my GIST above, I redirect all non secure requests over to a secure connection and as I have 0 subdomains, I redirect them all to my main domain name. You can edit as you see fit, but it should give you a good idea.

Please note the fastcgi_pass PHP_FPM_IP:9000; section, in order to get your PHP_FPM_IP you will need to run the following…

docker network inspect bridge

Looking for the php7 container, you should see something similar to…

"Containers": { "5bdf47e8153e713281ef59defe394f32b6172ba80ea626898d1566daf3541322": { "Name": "nginx", "EndpointID": "61de2b82a696984286a0b0e912e2c869bf755afa4e74e246182eeca1ace8412c", "MacAddress": "02:42:ac:11:00:02", "IPv4Address": "172.17.0.2/16", "IPv6Address": "" }, "a814706d03e4583bf061229bbb8c872d5ccd70d1e8b38a28a8dd80b984192027": { "Name": "mariadb", "EndpointID": "1d33b48beed9b7a43ea48d8d0b89811d0978f4af4a840b1d60ce2b4125bc6fb4", "MacAddress": "02:42:ac:11:00:03", "IPv4Address": "172.17.0.3/16", "IPv6Address": "" }, "fe46b9bcc689ba7fce47abe73f870408876b1b9c84094d3763fbe9ff8b601f4a": { "Name": "php7", "EndpointID": "c35329419ed8652ac23cfba7f9808a27d248237f14cd1d14d5668e9c2069e310", "MacAddress": "02:42:ac:11:00:04", "IPv4Address": "172.17.0.4/16", "IPv6Address": "" } },

As you can see from the code above, my IP is… 172.17.0.4 so I would place that into my default.conf like…

fastcgi_pass 172.17.0.4:9000;

Now for copying the default.conf file…

docker cp default.conf nginx:/etc/nginx/conf.d/default.conf docker restart nginx

This will copy your file over to the correct location. A quick restart will ensure the new configuration has been loaded in.

If you are seeing a “502 Bad Gateway” then you will need to go into your php container and edit the file pemissions as follows…

UPDATE: If you pull down my latest Dockerfile, you will no longer need to perform these chown and chmod steps as it now does it inside of the Dockerfile.

docker exec -it php7 bash chown -R www-data public cd public sudo chmod -R gu+w storage sudo chmod -R guo+w storage

This should sort out your folder permissions and now you can drink a cup of tea and enjoy all of your hard work.

If you have any problems or would like to suggest anything, please feel free to comment below.

Hosting your site With Digital Ocean and Docker

Affiliate links:

Please be aware that the links in this article are affiliate links. If you click on them, I will gain some sort of commission. All money gained will help future blog posts.

Installing Docker on Digital Ocean

I want to share with you how I am hosting my website with Digital Ocean (hosting company) and Docker (places your app in containers).

First off, I created my droplet on DO and used the docker image from the list of “One-click Apps”. The droplet was the $10 a month size as I don’t currently need anything more. (If you want to try Docker for a month or two then click here).

Pull in an image

After going through the setup process, I accessed my server through SSH and downloaded the Ubuntu image.

docker pull ubuntu

Creating and setting up containers

Once I have downloaded the Ubuntu image, I created my own container. I know I could have pulled in the php-fpmcontainer (and I did), I couldn’t quite work out how I was supposed to get it working properly. So while this next part was really tedius, it has taught me a valuable lesson.

Onto the command for creating my container…

docker run -tid -p 80:80 -p 443:443 -v /home/project/public:/home/project/public --name CONTAINERNAME

Now my container is up and running and sharing my data with the server. I then mount the container by running…

docker attach CONTAINERNAME

Once in, I begin to install PHP 7, NGINX, PHP-FPM and everything else I need for hosting my site (the list is long as the Ubuntu image is barebones). I then add my server block info for http and https rules as well as subdomain redirects.

Detaching from Docker Containers

Once finished, I press…

ctrl+p ctrl+q

This will detach from your continer, but won’t stop any services. I would recommend you never type exit within the container if you want to keep it running along with it’s services.

Create a database container

Now we need a database container, I user MariaDB and followed the documentation from their Docker Hub page.

docker run -p 3306 --name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag --character-set-server=utf8mb4 --collation-server=utf8m4bd

This will create a container for your MariaDB database, you can then attach yourself to the container and create your personal database using the usual MySQL commands.

Now quit your database and detach from the container with…

ctrl+p ctrl+q

Then run…

docker network inspect bridge

It will list your containers and display your IP address. You need to look out for your MariaDB container and take not of your IP address. You can then edit your database configuration file and where it says DB_HOST. Place your IP here and along with your username/password details, it should connect.

Make sure to either run any migrations or export/import your database. And your website is now fully up and running on Docker instances.

As I become more acquainted with the behemouth that is Docker, I will create more tutorials with regards to what it is is I wanted to accomplish and how I did it.

Mounting Volumes in Docker and Using Windows 10

This is a quick post to details some issues I have found when trying to use Docker within a Mac or Windows environment.

I had been following this tutorial on how to get Laravel up and running on Docker. My first pain I came across has been shared with both Mac and Windows environments.

Basically, when you go to mount a volume, by default you can only mount local directories in your User folder. To fix this, you first need to open up your VirtualBox GUI. Click on your current VM and click on “Settings”, then head over to “Shared Folders”. When you get here, you will want to click on the plus symbol to add a new folder share. For me, I wanted to mount my sites directory which could be found in my d drive…

I’m not 100% sure if “Auto-mount” and “Make Permanent” really matter, but I ticked it any way.

Once done, you will need to type something similar to the following…

docker-machine ssh docker-vm 'sudo mount -t vboxsf d/sites/laravel //d/sites/laravel'

(Please note that the double // is for Windows only and isn’t needed in Mac. Also, you should rename “docker-vm” to whatever your vm is called.)

Now this has been done, you can mount your volume as needed.

Mounting your volume


Next up is a Windows only issue, this one is quick and easy, but can be frustrating when you can’t find the correct solution. If you are like me and run Docker using git bash, then you won’t be able to mount your volume in the normal way which is usually something like this…

docker run -tid -p 80:80 -v /d/sites/laravel:/var/www nimmis/apache-php5

You will revieve an error…

"invalid value "D:\sites\laravel;C:\Program Files\Git\var\www" for flag -v: bad mode specified: Program FilesGitvarwww See 'C:Program FilesDocker Toolboxdocker.exe run --help'."

Instead you need to add a double forward slash at the beginning so it ends up like this…

docker run -tid -p 80:80 -v //d/sites/laravel:/var/www nimmis/apache-php5

I hope you enjoyed this post. If you have anything you would like to add to it please feel free to leave a comment below.