0

I need to connect FTP server from my_go_app container. When I do it from it from docker compose, I can do it with:

apk add lftp
lftp -d ftp://julien:test@ftpd-server

and it connects well

but when I try to run my container via docker run, I cannot connect anymore to FTP server

Here the command I use:

docker run --name my_go_app --rm -v volume:/go my_go_app:exp --network=my_go_app_network --env-file ./test.env

Here is the working docker-compose.yml

version: '3'

services:
  my_go_app:
    image: my_go_app:exp
    volumes:
      - ./volume:/go
    networks:
      my_go_app_network:
    env_file:
      - test.env

  ftpd-server:
    container_name: ftpd-server
    image: stilliard/pure-ftpd:hardened
    ports:
      - "21:21"
      - "30000-30009:30000-30000"
    environment:
      PUBLICHOST: "0.0.0.0"
      FTP_USER_NAME: "julien"
      FTP_USER_PASS: "test"
      FTP_USER_HOME: "/home/www/julien"
    restart: on-failure
    networks:
      my_go_app_network:

networks:
  my_go_app_network:
    external: true

EDIT:

I added the network as external and created it manually with:

 docker network create my_go_app_network

Now it appears that my_go_app is part of the default network:

my_go_app git:(tests) ✗ docker inspect my_go_app -f "{{json .NetworkSettings.Networks }}"         
{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"62b2dff15ff00d5cd56c966cc562b8013d06f18750e3986db530fbb4dc4cfba7","EndpointID":"6d0a81a83cdf639ff13635f0a38eeb962075cd729181b7c60fadd43446e13607","Gateway":"172.17.0.1","IPAddress":"172.17.0.2","IPPrefixLen":16,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"02:42:ac:11:00:02","DriverOpts":null}}


➜  my_go_app git:(tests) ✗ docker network ls
  NETWORK ID          NAME                DRIVER              SCOPE
  62b2dff15ff0        bridge              bridge              local
  f33ab34dd91d        host                host                local
  ee2d604d6604        none                null                local
  61a661c82262        my_go_app_network      bridge              local

What am I missing ?

Juliatzin
  • 18,455
  • 40
  • 166
  • 325
  • I'm sorry if this is stating the obvious, but have you double-checked (with `docker ps`) that both containers are up and running as expected? Also, it's worth checking what is in each container's log - there are often useful clues there. – Vince Bowdren Jan 23 '19 at 10:13
  • yes both container are up, and nothing wrong in the logs – Juliatzin Jan 23 '19 at 10:57

1 Answers1

1

Your network my_go_app_network should be declared as "external", otherwise compose will create a network called "project_name_my_go_app_network". Therefore your go app was not in the same network with the ftp server.

(I guess you have created my_go_app_network manually so your docker run did not throw any network not found error.)

EDIT

You put the arguments in the wrong order. Image name has to be the last one, otherwise they are considered as "commands" for the container. Try

docker run --name my_go_app --rm -v volume:/go --network=my_go_app_network --env-file ./test.env my_go_app:exp

Siyu
  • 11,187
  • 4
  • 43
  • 55
  • Yes, they are not in the same network, but can't figure out why. I created a network manually and used it as external in docker compose, but when I execute docker run, it stills run in the default network, even if I use --network=my_go_app_network. Don't know why – Juliatzin Jan 23 '19 at 10:37
  • yep, that was the problem. Is there any additional restrictions about order ? any docs that mention it ? – Juliatzin Jan 23 '19 at 11:57
  • you can use `docker run --help` which gives you `docker run [OPTIONS] IMAGE [COMMAND] [ARG...]` – Siyu Jan 23 '19 at 12:33
  • @Siyuhi, can you have a quick look at my containerised ftp-server pls? https://stackoverflow.com/questions/64438942/nodejs-application-stops-working-when-containerised?noredirect=1#comment113946483_64438942 – DrkStr Oct 20 '20 at 10:18