如何在我的ubuntu容器中安装Docker? [英] How to install Docker inside my ubuntu container?

查看:72
本文介绍了如何在我的ubuntu容器中安装Docker?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将docker安装在运行在 ubuntu:18.04 上的容器中,以运行我的nodejs应用,我需要在该容器中安装docker,因为我需要对另一个小型应用进行Docker

I installed docker inside a container running on ubuntu:18.04 to run my nodejs app, I need docker installed inside this container because i need to dockerize an other small app

她是我的Dockerfile

Her is my Dockerfile

FROM ubuntu:18.04

WORKDIR /app

COPY package*.json ./

# Install Nodejs
RUN apt-get update
RUN apt-get -y install curl wget dirmngr apt-transport-https lsb-release ca-certificates software-properties-common gnupg-agent
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get -y install nodejs

# Install Chromium
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt-get update
RUN apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst \
      --no-install-recommends
RUN rm -rf /var/lib/apt/lists/*

# Install Docker
RUN curl -fsSL https:/download.docker.com/linux/ubuntu/gpg | apt-key add -
RUN apt-key fingerprint 0EBFCD88
RUN add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
RUN apt-get update -y
RUN apt-get install -y docker-ce docker-ce-cli containerd.io

RUN npm install

COPY . .

CMD [ "npm", "start" ]

EXPOSE 3000

当容器启动时,我 docker exec -it app bash .如果我执行 service docker start 然后 ps ax ,得到了

When the container is up, i docker exec -it app bash. If i do a service docker start then ps ax, got this

  PID TTY      STAT   TIME COMMAND
  115 ?        Z      0:00 [dockerd] <defunct>

我该怎么做才能在容器内使用docker或是否有一个不使用apk而是apt-get的docker镜像?因为当我需要使用它时,出现了以下错误:

What can i do to be able to use docker inside the container or is there a docker image not using apk but apt-get ? Because when i need to use it, i got this error :

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

推荐答案

最好使用其中一个基本映像,无论是节点映像并安装docker,并安装 docker映像和安装的节点,而不是从头开始创建映像.您需要的一切

First thing better to use one of the base images, either for node-image and install docker and for docker-image and installed node, instead of creating image from scratch. All you need

FROM  node:buster
RUN apt-get update 
RUN apt install docker.io -y
RUN docker --version
ENTRYPOINT nohup dockerd >/dev/null 2>&1 & sleep 10 && node /app/app.js


第二件事,错误无法连接到unix:///var/run/docker.sock上的Docker守护程序.docker守护进程正在运行吗?,原因是您没有在Dockefile中启动docker进程,也不建议在容器中运行多个进程,就好像Docker进程死了一样,您将不知道状态,您必须在后台放置一个进程.

second thing, The error Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?, The reason is you are not starting the docker process in the Dockefile, and also running multiple processes in the container is not recommended, as if Docker process dies you will not know the status, you have to put one process in the background.

CMD nohup dockerd >/dev/null 2>&1 & sleep 10 && node /app/app.js

然后运行

docker run --privileged  -it -p 8000:8000  -v /var/run/docker.sock:/var/run/docker.sock your_image

这篇关于如何在我的ubuntu容器中安装Docker?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆