Setup Docker/Ngnix and Let's Encrypt on Ubuntu¶
This is a note for setting up a Docker, Nginx and Let's Encrypt environment on Ubuntu 20.04 LTS.
Create a Ubuntu 20.04 LTS instance¶
Install Docker using the convenience script¶
1 2 |
|
Manage Docker as a non-root user¶
If you don't want to preface the docker
command with sudo
, create a Unix group called docker
and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker
group.
To create the docker
group and add your user:
- Create the
docker
group.
1 |
|
- Add your user to the
docker
group.
1 |
|
-
Log out and log back in so that your group membership is re-evaluated.
On Linux, you can also run the following command to activate the changes to groups:
1 |
|
Configure Docker to start on boot¶
1 |
|
To disable this behavior, use disable
instead.
1 |
|
Install Docker Compose¶
On Linux, you can download the Docker Compose binary from the Compose repository release page on GitHub. Follow the instructions from the link, which involve running the curl
command in your terminal to download the binaries. These step-by-step instructions are also included below.
- Run this command to download the current stable release of Docker Compose:
Note
To install a different version of Compose, substitute 1.25.5
with the version of Compose you want to use.
- Apply executable permissions to the binary:
1 |
|
Note
If the command docker-compose
fails after installation, check your path. You can also create a symbolic link to /usr/bin
or any other directory in your path. For example:
1 |
|
Set up Nginx-Proxy¶
Create a unique network for nginx-proxy and other Docker containers to communicate through.
1 |
|
Create a directory nginx-proxy
for the compose file.
1 |
|
In the nginx-proxy directory, create a new file named docker-compose.yml
and paste in the following text:
example docker-compose.yml
for nginx-proxy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
Inside of the nginx-proxy
directory, use the following curl
command to copy the developer’s sample nginx.tmpl
file to your VPS.
1 |
|
Increase upload file size
To increase the maximum upload size, for example, add
client_max_body_size 100M;
to theserver{}
section in thenginx.tmpl
template file. For WordPress,
Running nginx-proxy
.
1 |
|
Add a WordPress container¶
Create a directory for the docker-compose.yml
with:
example docker-compose.yml
for WordPress container
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
To create a second WordPress container, add MYSQL_TCP_PORT
environment variable and set it to a different port.
Increase maximum WordPress upload file size¶
Enter the bash of the WordPress container.
1 |
|
Move inside your /var/www/html directory (already there if you’re using the standard Docker Compose image). Run the following command to insert the values.
1 |
|
Note
To restore the values, run $ sed -i "11,12d" .htaccess