Add a Docker container
This topic is a quick guide for installing Docker and adding a container to a tailnet. For more detailed information, see Using Tailscale with Docker. For more information about using Docker products in general, see the official Docker documentation.
Install Docker
-
Download Docker on a Linux device or a cloud VM:
curl -fsSL https://get.docker.com -o install-docker.sh
-
Run the Docker installation script:
sudo sh install-docker.sh
-
Enter your password when prompted.
-
Modify your user Linux user group permission for Docker to interact with it without needing to use
sudo
.sudo usermod -aG docker username
We highly recommend you also refer to the Docker topic Manage Docker as a non-root user for more information.
-
Log out of the terminal session then log back in to allow the permission change to occur.
-
Run the follow command to verify that the Docker Engine is installed:
docker run --rm hello-world
Create a container for Tailscale
You can use Docker to deploy containers for many kinds of use cases. The instructions below explain how to configure an Ngnix web server and connect it to your tailnet.
-
Create a Docker compose
yaml
file using your preferred terminal text editor:vi docker-compose.yaml
-
In the
yaml
file, replace the sample auth key in theTS_AUTHKEY
field, with your own. To do this, open the Keys page of the admin console. Select Generate auth key, provide a key name, toggle Resusable to on, and select Generate key. Copy the key and paste it into theTS_AUTHKEY
field in theyaml
file. -
In the
yaml
file, make sure the service name (immediately belowservices
) matches thenetwork_mode
field.This
yaml
file is instructing Docker to create an Nginx web server container with the hostnamebanana
and add it to the tailnet. -
Save the changes in your
yaml
file. -
Start up the container and wait for the process to complete:
docker compose up -d
-
Open the Machines page of the admin console, and you should now see the node
banana
added to the list.
You can now verify that the Nginx web server is available by going to http://hostname
(in this case hostname is banana
) and you should see a "Welcome to ngnix" page display.