This configuration can be used for hosting multiple sites on a single server, using docker and docker-compose for each site. Each site needs a unique port, and will be served on a unique domain. For SSL, use Cloudflare as a proxy.
Use EC2 to create a new instance. The image should be Amazon Linux 2 on ARM, running on a t4g.nano/t4g.micro/t4g.small. n.b. t4g.small is free for 750h/mo until the end of 2023. These cost $0.0042, $0.0084 and $0.0168 per hour respectively, or $3.066, $6.132 and $12.264 per month respectively. Use an Elastic IP address to maintain a constant IP address. You should expose only the ports 80 and 443 to the world (HTTP/S), and the port 22 (SSH) to yourself. The script can then be copied directly in to the shell when you are ssh’ed in.
Once a site has been started with docker-compose, exposing a port internally, use the command add-site domain-name port
(e.g. add-site my.website.com 8080
) to register this with Apache.
This means that any requests to my.website.com will be forwarded to your container running on the given port (e.g. 8080).
Note that the docker-compose file should include restart: always
to ensure that it runs when the instance is restarted.
Use the command list-sites
to list all registered sites.
If you attempt to start two Docker projects with the same IP address, docker-compose will probably complain.
However, add-site
can be used to bind arbitrarily many domains to the same internal port.
In order to change the port for a given domain, simply call add-site
again, and it will be overwritten.
To delete a site, delete the relevant file in /etc/httpd/conf.d/
.
E.g. to delete my.website.com
, run sudo rm /etc/httpd/conf.d/domain-name.conf
.
Web sockets are also supported, but please let me know if anything doesn’t work.
Run the attached deploy
script, with the following environment variables set. These variables can also be read from a .ec2-deploy
file in the current directory (if not already set in the environment).
DOMAIN
: The domain name that will be used to access the siteDEPLOY_HOST
: The address used for connecting to the server push the changesDEPLOY_USER
: The user of the server. OptionalDEPLOY_KEYPAIR
: The PEM file (ssh-i
flag) for connecting to the server. OptionalDEPLOY_DIR
: The path on the remote server to deploy underSERVER_PORT
: The port exposed by docker-compose. This must be unique among VMs on the server.PORT_VARIABLE
: The name of the environment variable used for passing$SERVER_PORT
to the docker-compose command. E.g. IfPORT_VARIABLE=APP_PORT
, docker-compose.yaml could contain the entryservices.app.ports
of"${APP_PORT:-5000}:5000"
.SOURCE_DIR
: The local directory to deploy.
Todo: add notes about creating new users. Fairly simple:
Add new keypair