我在运行的容器内安装了 dockerubuntu:18.04
要运行我的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
then 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?
首先最好使用一个基本图像,无论是节点图像 https://hub.docker.com/_/node并安装 docker 和docker镜像 https://hub.docker.com/_/docker并安装节点,而不是从头开始创建映像。一切你需要的
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
and run
docker run --privileged -it -p 8000:8000 -v /var/run/docker.sock:/var/run/docker.sock your_image
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)