Docker: Getting started

Fast, secure remote Docker management with Stackhero for Docker

Welcome to the Stackhero documentation

Stackhero offers a ready-to-use Docker cloud CaaS (Containers as a Service) platform, designed for fast and reliable container deployments:

  • Deploy to production with a single docker-compose up command. No additional configuration required: just launch your containers.
  • Choose your own domain name, automatically secured with HTTPS (for example: https://api.your-company.com, https://www.your-company.com, or https://backoffice.your-company.com).
  • Take advantage of high performance and enhanced security on private, dedicated infrastructure.
  • Apply updates with a single click for simple, effortless maintenance.

Your containers can be running in production in about five minutes. Stackhero manages the infrastructure, updates, and security for you, so you can focus on developing your applications. Learn more about Docker CaaS cloud hosting.

Docker CLI must be installed on your computer. If you have not done so yet, you can download it from the official Docker website: Docker Desktop.

With Stackhero for Docker, you can manage your containers remotely using the Docker CLI, just as you would locally. This allows you to keep your usual workflow while running commands directly on your production-ready Docker server, securely and efficiently.

Docker "contexts" make this possible. Contexts let you specify to the Docker CLI where to send your commands: either to your local Docker daemon or to your Stackhero for Docker instance. Switching contexts is quick and seamless.

To connect securely to your Stackhero for Docker instance, you need to install its certificates on your computer. These certificates ensure authentication and encryption, keeping your connection private and secure.

You can use the following command to download and install the certificates:

# HOST is your Docker instance domain name (<XXXXXX>.stackhero-network.com).
# SERVICE_ID is your Stackhero service ID.
# CERTIFICATES_PASSWORD is the password set in your Docker configuration on the Stackhero dashboard.
(export HOST="<XXXXXX>.stackhero-network.com"
export SERVICE_ID="<SERVICE_ID>"
export CERTIFICATES_PASSWORD="<CERTIFICATES_PASSWORD>"

cd /tmp/ \
  && curl -o certificates.tar https://docker:$CERTIFICATES_PASSWORD@$HOST/stackhero/docker/certificates.tar \
  && tar -xf certificates.tar \
  && (docker context rm -f $HOST 2> /dev/null || true) \
  && docker context create $HOST \
    --description "$SERVICE_ID ($HOST)" \
    --docker "host=tcp://$HOST:2376,ca=ca.pem,cert=cert.pem,key=key.pem")

This command creates a Docker context named after your service domain. You can list all available contexts with:

docker context ls

If you change your service domain, your certificates will be renewed. You will need to reinstall them to reconnect securely.

By default, the docker ps command shows containers running on your local machine. For example, running:

docker run --rm alpine wget -q -O - ifconfig.me

returns your local public IP, since the container runs on your computer.

To work remotely, switch your Docker context to your Stackhero for Docker instance:

docker context use <XXXXXX>.stackhero-network.com

Now, every Docker CLI command will execute on your remote Docker server. Running the same IP check command:

docker run --rm alpine wget -q -O - ifconfig.me

will display your Stackhero for Docker instance's public IP. This confirms your containers are running on the remote server.

To switch back to your local Docker daemon, simply run:

docker context use default

When you mount a volume in a remote container, the files available are from the remote server, not your local machine. For example, docker run -it -v ${PWD}:/mnt alpine will mount the remote directory, not your current local directory.

Docker Compose also uses the active Docker context. Once you set the context to the remote instance with:

docker context use <XXXXXX>.stackhero-network.com

every Docker Compose command you run will operate on your remote server. This allows you to deploy multi-container applications just as easily as you would locally, but directly on your production environment.

Switching contexts with docker context is convenient for interactive use. For scripts or Makefiles, the DOCKER_CONTEXT environment variable gives you additional control. You can find more details in our advanced documentation.

For more information on Docker contexts, the official Docker documentation on contexts provides further details.