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.
Install Docker using the convenience script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
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.
sudo groupadd docker
- Add your user to the
docker
group.
sudo usermod -aG docker $USER
-
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:
newgrp docker
Configure Docker to start on boot
sudo systemctl enable docker
To disable this behavior, use disable
instead.
sudo systemctl disable docker
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:
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
- Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
Set up Nginx-Proxy
Create a unique network for nginx-proxy and other Docker containers to communicate through.
docker network create nginx-proxy
Create a directory nginx-proxy
for the compose file.
mkdir nginx-proxy && cd nginx-proxy
In the nginx-proxy directory, create a new file named docker-compose.yml
and paste in the following text:
Inside of the nginx-proxy
directory, use the following curl
command to copy the developer’s sample nginx.tmpl
file to your VPS.
curl https://raw.githubusercontent.com/jwilder/nginx-proxy/master/nginx.tmpl > nginx.tmpl
Running nginx-proxy
.
docker-compose up -d
Add a WordPress container
Create a directory for the docker-compose.yml
with:
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.
docker exec -t wordpress_container_name bash
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.
sed -i '/^# END WordPress.*/i php_value upload_max_filesize 256M\nphp_value post_max_size 256M' .htaccess