Search code examples
dockerdokku

Error trying to link a container using Dokku


I am trying to create a link to access a service running in another container. The command I am using is:

dokku docker-options:add service deploy,build,run --link service.unoserver.1:unoserver_host

and then

dokku ps:restart service

However, for some reason, dokku keeps adding a number at the end of the container's name (problbly the name of the replacing container) and I receive the following error message:

Error message:

Error response from daemon: Cannot link to a non running container: /service.unoserver.1.1695992273 AS /sevice.prepareworker.1/unoserver_host

Question:

How can I link the container service.unoserver.1 so I can access it from the container service.preparewoker.1?

docker container ls

CONTAINER ID   IMAGE                         COMMAND                  CREATED         STATUS         PORTS      NAMES
f47bb2ec5626   dokku/service:latest   "unoserver --interfa…"   6 minutes ago   Up 6 minutes   5000/tcp   service.unoserver.1
d35c1a242d52   dokku/service:latest   "python manage.py ru…"   6 minutes ago   Up 6 minutes   5000/tcp   service.prepareworker.1

Solution

  • Networking across containers requires a stable container name when using docker link. For this reason, Dokku only uses them for service linking.

    If you want to network across apps, you’ll want to use networks. The following would be enough to create a network and add your app to it:

    # create a network named my-network
    dokku network:create my-network
    
    # attach the app to it
    dokku network:set node-js-app attach-post-deploy my-network
    

    From then on, the app node-js-app would be accessible on the network at http://node-js-app.web:5000, where web is the process type and 5000 is the port the app is listening on inside the container. You can attach other apps to that same network to connect to this service.

    See the dokku network management docs for more details on how this works.