使用docker和docker compose创建映像

问题描述 投票:0回答:3

我是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

码头图片

enter image description here

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 docker-compose
3个回答
0
投票

构建命令应为:

docker build -t toto/test-sample .

0
投票

[使用如下所示的docker文件构建docker映像时,必须提供标签名称:

docker build -t toto/test-sample -f Dockerfile .

-t这是标签名称-f此处用于告诉Dockerfile的名称(在这种情况下,它是可选的,因为Dockerfile是默认名称)


0
投票

如果将Dockerfiledocker-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 .
© www.soinside.com 2019 - 2024. All rights reserved.