我是Docker的新手,我试图创建一个Docker映像并使用Docker容器,所以我做了以下工作:
我的Dockerfile是:
FROM ubuntu:16.04
# # Front stack
# RUN apt-get install -y npm && \
# npm install -g @angular/cli
FROM python:3.6
RUN apt-get update
RUN apt-get install -y libpython-dev curl build-essential unzip python-dev libaio-dev libaio1 vim
rpm2cpio cpio python-pip dos2unix
RUN mkdir /code
COPY ./requirements.txt /code/requirements.txt
RUN pip install -r /code/requirements.txt
RUN pip install --upgrade pip
COPY . /code/
WORKDIR /code
ENV PYTHONPATH=/code/py_lib
CMD ["bash", "-c", "tail -f /dev/null"]
我的dockerCompose文件是:
version: '3.5'
services:
testsample:
image: toto/test-sample
restart: unless-stopped
env_file:
- .env
command: bash -c "pip3 install -r requirements.txt && tail -f /dev/null"
# command: bash -c "tail -f /dev/null"
volumes:
- .:/code
我执行了这些命令:
docker build。 -f Dockerfile
码头图片
docker-compose up
这给了我一个错误:
Pulling testsample (toto/test-sample:)...
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume
data could be lost. Consider backing up your data before continuing.
Continue with the new image? [yN]y
Pulling testsample (toto/test-sample:)...
ERROR: pull access denied for toto/test-sample, repository does not exist or may require 'docker
login': denied: requested access to the resource is denied
我尝试了docker登录并可以连接。
那么会导致什么问题呢?
构建命令应为:
docker build -t toto/test-sample .
[使用如下所示的docker文件构建docker映像时,必须提供标签名称:
docker build -t toto/test-sample -f Dockerfile .
-t这是标签名称-f此处用于告诉Dockerfile的名称(在这种情况下,它是可选的,因为Dockerfile是默认名称)
如果将Dockerfile
与docker-compose.yml
文件放在同一目录中,则可以执行以下操作:
version: '3.5'
services:
testsample:
image: toto/test-sample
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
env_file:
- .env
volumes:
- .:/code
然后,执行:
docker-compose up --build -d
否则,如果您只是在构建图像时遇到问题,则只需要这样做:
docker build -t toto/test-sample .