How to run a Docker container
Docker lets you run a custom, containerized application on an application. TurboStack runs the container and Nginx reverse-proxies public traffic to it, so it gets HTTPS, caching and the security layers like any other site. Use it for apps that ship as a container rather than as a standard PHP or runtime app.
Before you start
-
SSH access to the host as the application's system user - see SSH access.
-
A container image you can pull, and the port it listens on inside the container.
-
A free local port on the host to publish it on (
8080in the examples below).
1. Enable Docker for the application
Turn on Docker under Configure application > Technologies > Docker (see
Configure Docker). Every system user with Docker enabled is added to the docker
group and can run the docker commands over SSH.
2. Run the container
Connect over SSH and start your container. Bind its port to localhost so it is only reachable through Nginx, and set a restart policy so it comes back after a reboot:
docker run -d \
--name myapp \
--restart unless-stopped \
-p 127.0.0.1:8080:80 \
your-image:1.2
-druns it in the background;--namegives it a stable name.-p 127.0.0.1:8080:80publishes the container's port80on host port8080, localhost only.--restart unless-stoppedstarts the container again automatically, for example after a reboot.- Pin a specific image tag (
your-image:1.2) rather thanlatest, so deployments are reproducible.
3. Publish it through TurboStack
Point the reverse proxy at the port you published, so Nginx serves the app on your domain with HTTPS:
docker_enabled: true
proxy_enabled: true
proxy_upstream_port: 8080 # the host port you published above
Publish the change to apply it.
Keep data in a volume
Anything written inside the container is lost when it is recreated. Store data you need to keep in a named volume, mounted into the container:
docker run -d --name myapp -v myapp_data:/data your-image:1.2
Manage the container
docker ps # running containers
docker ps -a # all containers, including stopped ones
docker logs -n 100 myapp # recent logs
docker stop myapp # stop
docker start myapp # start
docker rm myapp # remove (stop it first)
Tip
Run one main process per container and keep images small and purpose-built. For anything TurboStack manages for you - databases, cache, PHP - use the built-in technologies instead of a container.
Apply and verify
docker ps lists the container as Up. From the host, the published port answers:
curl -I http://127.0.0.1:8080
Once the reverse proxy is published, the same page loads on your domain over HTTPS.
If it did not work
A 502 on your domain means Nginx reached the port but nothing answered. Check that the container
is running with docker ps -a, and that it listens on the port you published, not another one.
docker logs -n 100 myapp shows why a container stopped. See
Fixing 502, 503 and 504 errors, or
contact support.