【问题标题】:How to install Docker inside my ubuntu container?如何在我的 ubuntu 容器中安装 Docker?
【发布时间】:2019-12-04 11:19:45
【问题描述】:

我在ubuntu:18.04 上运行的容器中安装了 docker 来运行我的 nodejs 应用程序,我需要在这个容器中安装 docker 因为我需要对另一个小应用程序进行 dockerize 处理

她是我的 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,得到这个

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

我该怎么做才能在容器内使用 docker 或者是否有一个 docker 映像不使用 apk 而是 apt-get ? 因为当我需要使用它时,我收到了这个错误:

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

【问题讨论】:

标签: docker ubuntu containers


【解决方案1】:

首先最好使用一个基础镜像,用于node-image 并安装 docker 和docker-image 并安装节点,而不是从头开始创建镜像。你所需要的一切

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


第二件事,错误Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?,原因是你在Dockefile中没有启动docker进程,也不建议在容器中运行多个进程,如果docker进程死了你就不会知道状态,您必须在后台放置一个进程。

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

【讨论】:

  • 这种方法的问题是我无法使用应用容器中的 127.0.0.1:port 卷曲我需要的容器
  • 你需要在哪里卷曲?您是否公开了所需的端口?
  • 我暴露了所有需要的东西,我需要从 myapp 容器中卷曲。如果我从本地主机 curl 127.0.0.1:5001 它可以工作,如果我从容器 myapp 卷曲我得到一个错误
  • 你试过curl localhost:5001吗?你能证明你正在尝试打电话吗?
  • 所以,我需要在我的 nodejs 应用程序中使用多个代理来抓取 google 页面结果。这是我的代理容器d314610709fb pry0cc/proxydock "supervisord -n" 22 hours ago Up 22 hours 127.0.0.1:5002-&gt;8080/tcp proxy_50021548f448a1b5 pry0cc/proxydock "supervisord -n" 22 hours ago Up 22 hours 127.0.0.1:5001-&gt;8080/tcp proxy_5001
猜你喜欢
  • 2022-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-11
  • 1970-01-01
  • 1970-01-01
  • 2021-08-06
  • 2021-09-05
相关资源
最近更新 更多