execute a command within docker swarm service

后端 未结 11 1786
眼角桃花
眼角桃花 2020-12-04 15:16
  1. Initialize swarm mode:

    root@ip-172-31-44-207:/home/ubuntu# docker swarm init --advertise-addr 172.31.44.207
    
    Swarm initialized: current node (4mj61o         
    
    
            
11条回答
  •  暖寄归人
    2020-12-04 16:05


    EDIT 2017-10-06:

    Nowadays you can create the overlay network with --attachable flag to enable any container to join the network. This is great feature as it allows a lot of flexibility.

    E.g.

    $ docker network create --attachable --driver overlay my-network
    $ docker service create --network my-network --name web --publish 80:80 nginx
    $ docker run --network=my-network -ti alpine sh
    (in alpine container) $  wget -qO- web
    
    
    
    
    ....
    

    You are right, you cannot run docker exec on docker swarm mode service. But you can still find out, which node is running the container and then run exec directly on the container. E.g.

    docker service ps miniconda3  # find out, which node is running the container
    eval `docker-machine env `
    docker ps  # find out the container id of miniconda
    docker exec -it  sh
    

    In your case you first have to find out, why service cannot get the miniconda container up. Maybe running docker service ps miniconda3 shows some helpful error messages..?

提交回复
热议问题