docker error: /var/run/docker.sock: no such file or directory

后端 未结 11 986
轻奢々
轻奢々 2020-12-07 14:52

I am new to docker. I have a shell script that loads data into impala and I want a docker file that runs builds an image and run the container. I am on mac, installed boot2d

相关标签:
11条回答
  • 2020-12-07 15:36

    If you're using CentOS 7, and you've installed Docker via yum, don't forget to run:

    $ sudo systemctl start docker
    $ sudo systemctl enable docker
    

    This will start the server, as well as re-start it automatically on boot.

    0 讨论(0)
  • 2020-12-07 15:37

    The first /var/run/docker.sock refers to the same path in your boot2docker virtual machine. Correcly write for windows /var/run/docker.sock

    0 讨论(0)
  • 2020-12-07 15:37

    You, maybe the not the OP, but someone may have a directory called /var/run/docker.sock/ already due to how many times you hack and slash to get things right with docker (especially noobs). Delete that directory and try again.

    This helped me on my way to getting it to work on Centos 7.

    0 讨论(0)
  • 2020-12-07 15:38

    You don't need to run any docker commands as sudo when you're using boot2docker as every command passed into the boot2docker VM runs as root by default.

    You're seeing the error when you're running as sudo because sudo doesn't have the DOCKER_HOST env set, only your user does.

    You can confirm this by doing a:

    $ env
    

    Then a

    $ sudo env
    

    And looking for DOCKER_HOST in each output.

    As for having a docker file that runs your script, something like this might work for you:

    Dockerfile

    FROM busybox
    
    # Copy your script into the docker image
    ADD /path/to/your/script.sh /usr/local/bin/script.sh
    
    # Run your script
    CMD /usr/local/bin/script.sh
    

    Then you can run:

    docker build -t your-image-name:your-tag .
    

    This will build your docker image, which you can see by doing a:

    docker images
    

    Then, to run your container, you can do a:

    docker run your-image-name:your-tag
    

    This run command will start a container from the image you created with your Dockerfile and your build command and then it will finish once your script.sh has finished executing.

    0 讨论(0)
  • 2020-12-07 15:39

    To setup your environment and to keep it for the future sessions you can do:

    echo 'export DOCKER_HOST="tcp://$(boot2docker ip 2>/dev/null):2375";' >> ~/.bashrc
    

    Then: source ~/.bashrc

    And your environment will be setup in every session

    0 讨论(0)
提交回复
热议问题