0

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

enter image description here

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?

3 Answers 3

2

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)

Sign up to request clarification or add additional context in comments.

1 Comment

While this is true for single staged Docker builds, the Multi Staged Dockerfile he is using here makes it more difficult. docker build -t will only tag the first image FROM ubuntu. He needs to specify the tags inside the docker-compose.yaml and build with docker-compose build (do only generate two tagged seperate images)
1

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 .

Comments

0

build command should be:

docker build -t toto/test-sample .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.