简体   繁体   中英

Creating image with docker and docker compose

I am novice with Docker and I am trying to create a docker image and use the docker container so I did the following:

My Dockerfile is:

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"]

My dockerCompose file is:

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

I executed these commands:

docker build. -f Dockerfile

docker images

在此处输入图像描述

docker-compose up

This gave me an error:

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

I tried docker login and I am able to connect.

So what would lead to this problem?

build command should be:

docker build -t toto/test-sample .

You have to provide tag name when you are building a docker image using a docker file like the following:

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

-t here is for the tag name -f here is for telling the name of the Dockerfile (in this case it is optinal as Dockerfile is the default name)

If you put the Dockerfile in the same directory as your docker-compose.yml file, you can do the following:

version: '3.5'
services:
   testsample:
       image: toto/test-sample
       build:
         context: .
         dockerfile: Dockerfile
       restart: unless-stopped
       env_file:
         - .env        
       volumes:
         - .:/code

Then, do:

docker-compose up --build -d

Otherwise, if you are simply having problems building the image, you just need to do:

docker build -t toto/test-sample .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM