rota90
rota90

Reputation: 259

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

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?

Upvotes: 0

Views: 1350

Answers (3)

richyen
richyen

Reputation: 10048

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 .

Upvotes: 1

Chirag Bhatia
Chirag Bhatia

Reputation: 79

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)

Upvotes: 2

ozlevka
ozlevka

Reputation: 2156

build command should be:

docker build -t toto/test-sample .

Upvotes: 0

Related Questions