Fail to run docker while building an image

前端 未结 3 1969
既然无缘
既然无缘 2021-01-22 02:54

I tried to install a software with Docker while building an image and I get.

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. 
Is the         


        
3条回答
  •  北海茫月
    2021-01-22 03:19

    Ran into a similar challenge and these are the options I think:

    1. You can set the DOCKER_HOST environment variable in your dockerfile to an ip or host available outside the docker container. This is still not a flawless idea since that host will have to basically be available separately from the docker host. If you had a shared dockerhost in your enterprise that everyone could use for this then it might be fine but otherwise you're creating a somewhat complicated build system.

    2. Create a separate shell script to run the docker command outside the docker container build. Then copy the artifacts created by that step during your docker build. Not great because it's not 100% docker but still works good and is portable.

    3. Use sed with a dockerfile.template to inject the contents of the other dockerfile into your own dockerfile before doing a build. Like option 2 this still requires a pre build step and could also run into compatibility issues if you're not using the same OS in both dockerfiles.

    Given these 3 options option 2 seems like the best one.

提交回复
热议问题