Home Explore Blog CI



docker

2nd chunk of `content/guides/traefik.md`
d9cb73d0f53bc7ec3413a0f534c39d3734d6f282c59a9e650000000100000835
   ```console
   $ docker network create traefik-demo
   ```

2. Start a Traefik container using the following command. The command exposes Traefik on port 80, mounts the Docker socket (which is used to monitor containers to update configuration), and passes the `--providers.docker` argument to configure Traefik to use the Docker provider.

   ```console
   $ docker run -d --network=traefik-demo -p 80:80 -v /var/run/docker.sock:/var/run/docker.sock traefik:v3.1.2 --providers.docker
   ```

3. Now, start a simple Nginx container and define the labels Traefik is watching for to configure the HTTP routing. Note that the Nginx container is not exposing any ports.

   ```console
   $ docker run -d --network=traefik-demo --label 'traefik.http.routers.nginx.rule=Host(`nginx.localhost`)' nginx
   ```

   Once the container starts, open your browser to [http://nginx.localhost](http://nginx.localhost) to see the app (all Chromium-based browsers route \*.localhost requests locally with no additional setup).

4. Start a second application that will use a different hostname.

   ```console
   $ docker run -d --network=traefik-demo --label 'traefik.http.routers.welcome.rule=Host(`welcome.localhost`)' docker/welcome-to-docker
   ```

   Once the container starts, open your browser to http://welcome.localhost. You should see a “Welcome to Docker” website.

## Using Traefik in development

Now that you’ve experienced Traefik, it’s time to try using it in a development environment. In this example, you will use a sample application that has a split frontend and backend. This app stack has the following configuration:

1. All requests to /api to go to the API service
2. All other requests to localhost go to the frontend client
3. Since the app uses MySQL, db.localhost should provide phpMyAdmin to make it easy to access the database during development



The application can be accessed on GitHub at [dockersamples/easy-http-routing-with-traefik](https://github.com/dockersamples/easy-http-routing-with-traefik).

Title: Using Traefik: Example with Nginx and Docker Welcome App
Summary
The text demonstrates using Traefik to route traffic to multiple Docker containers based on hostnames. It shows how to start an Nginx container and the 'Welcome to Docker' app, configuring Traefik via Docker labels to route requests to each container based on the hostname (nginx.localhost and welcome.localhost, respectively). Additionally, it introduces a development environment example with a split frontend and backend application, showcasing how Traefik can route requests based on the path (/api) or hostname (db.localhost) to different services (API, frontend, and phpMyAdmin).