Closed cybtachyon closed 3 years ago
Hi @cybtachyon,
The example in readme is for routing handling to a standalone container launched via docker run
.
io.docksal.project-root
and --network
are only necessary for docker-compose
based stacks. That is all handled by fin
in the context of a Docksal based project.
If you were aiming at providing an example for an arbitrary docker-compose based stack (outside of Docksal), then that would need be covered as a separate use case in README. Is this a use case you and/or your team is exploring or actively using today? I'm curious about the reasoning behind using docksal/vhost-proxy outside of Docksal.
If you were aiming at providing an example for an arbitrary docker-compose based stack (outside of Docksal), then that would need be covered as a separate use case in README.
I'm not sure how that's a separate use-case, it's needed to connect a container to the network when using a docker run command irrespective of docker-compose. The compose project entry is required to have this vhost proxy service work properly when the container is added to the network, since the vhost proxy reads the project string.
Is this a use case you and/or your team is exploring or actively using today? I'm curious about the reasoning behind using docksal/vhost-proxy outside of Docksal.
Yes, we have a number of docksal Drupal projects that have dependencies on other services. Those services are maintained by other teams and are expensive to run locally, so they are only cloned and instantiated if absolutely necessary for a bug fix or feature development. We're using a docker run command to arbitrarily add a standalone container to the network for this use case, and would not want to incur the expense of development time adding it to main Drupal repos that support docksal as a local development environment.
it's needed to connect a container to the network when using a docker run command irrespective of docker-compose.
Docker creates the default bridge
network and attached any container launched with docker run
to that network. docksal-vhost-proxy
gets attached to the bridge
network as well and thus can talk to any other standalone container by default.
$ docker run -d --name=podinfo \
--label=io.docksal.virtual-host=podinfo.docksal.site \
--label=io.docksal.virtual-port=9898 \
--expose 9898 \
stefanprodan/podinfo
323d7962fca0f61fd6748fa4d8bbd589874f0c2d6c3e506af7ee609d86e6941c
$ curl -I -X GET podinfo.docksal.site
HTTP/1.1 200 OK
Server: openresty/1.17.8.1
Date: Wed, 26 May 2021 01:46:30 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 340
Connection: keep-alive
X-Content-Type-Options: nosniff
Now if you use docker-compose to launch containers, you will indeed have to either:
docksal-vhost-proxy
to the project's network created by docker-composedocker-compose.yml
definition:# test_default is an existing network from another Docksal managed project
# docksal-vhost-proxy is already attached to this network (handled by fin)
$ docker network ls | grep test_default
972f1aab210d test_default bridge local
$ cat docker-compose.yml
version: "3"
networks:
default:
external: true
name: test_default
services:
web:
image: stefanprodan/podinfo
expose:
- 9898
labels:
- "io.docksal.virtual-host=podinfo-project.docksal.site"
- "io.docksal.virtual-port=9898"
$ docker compose up -d
Docker Compose is now in the Docker CLI, try `docker compose up`
Creating podinfo_web_1 ... done
$ curl -I -X GET http://podinfo-project.docksal.site
HTTP/1.1 200 OK
Server: openresty/1.17.8.1
Date: Wed, 26 May 2021 01:52:53 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 340
Connection: keep-alive
X-Content-Type-Options: nosniff
Unfortunately, docker does not allow using the default bridge
network as external for some reason.
Note that both io.docksal.virtual-host and io.docksal.project-root are required labels for service containers. Note that io.docksal.project-root is a supported label. Note that a network needs to be added by the name of "${COMPOSE_PROJECT_NAME}_default". Provide example docker command and docker-compose yaml in the README.
Fixes #71 .