Can't connect to docker from docker-compose

前端 未结 24 2116
说谎
说谎 2020-12-07 10:14

I installed docker-machine 0.1.0 and docker-compose 1.1.0 on Mac OS 10.8.5.
Docker-machine is running normally and able to connect by docker-machine ssh.



        
24条回答
  •  广开言路
    2020-12-07 10:57

    Simple solution for me: sudo docker-compose up


    UPDATE 2016-3-14: At some point in the docker install process (or docker-compose ?) there is a suggestion and example to add your username to the "docker" group. This allows you to avoid needing "sudo" before all docker commands, like so:

    ~ > docker run -it ubuntu /bin/bash
    root@665d1ea76b8d:/# date
    Mon Mar 14 23:43:36 UTC 2016
    root@665d1ea76b8d:/# exit
    exit
    ~ > 
    

    Look carefully at the output of the install commands (both docker & the 2nd install for docker-compose) and you'll find the necessary step. It is also documented here: https://subosito.com/posts/docker-tips/

    Sudo? No!

    Tired of typing sudo docker everytime you issue a command? Yeah, there is a way for dealing with that. Although naturally docker is require a root user, we can give a root-equivalent group for docker operations.

    You can create a group called docker, then add desired user to that group. After restarting docker service, the user will no need to type sudo each time do docker operations. How it looks like on a shell commands? as a root, here you go:

    > sudo groupadd docker
    > sudo gpasswd -a username docker
    > sudo service docker restart 
    

    Done!

    UPDATE 2017-3-9

    Docker installation instructions have been updated here.

    Post-installation steps for Linux

    This section contains optional procedures for configuring Linux hosts to work better with Docker.

    Manage Docker as a non-root user

    The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user.

    If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.

    To create the docker group and add your user:

    # 1. Create the docker group.
    $ sudo groupadd docker
    
    # 2. Add your user to the docker group.
    $ sudo usermod -aG docker $USER
    
    # 3. Log out and log back in so that your group membership is re-evaluated.
    
    # 4. Verify that you can run docker commands without sudo.
    $ docker run hello-world
    

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

提交回复
热议问题