Creating image with docker and docker compose

docker-compose build image name
docker build
docker-compose up --build
dockerfile
docker-compose -f flag
install docker compose
docker-compose specify file
docker-compose build --no-cache

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?

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)

docker-compose build, update our existing docker-compose.yml file so that it builds a custom image; add instructions to a Dockerfile that Docker Compose follows to build a new image  Docker Compose then allows you to start the whole application with a single command! You start by creating a Dockerfile, to build docker images of your application – or you can use existing images from a registry. You then define your docker services that you need to run your app in a docker-compose.yml file (see example later).

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 .

How to understand building images with docker-compose, What the above does is instruct Docker Compose to deploy a container using the official nginx image. We're not doing anything special for this  image=app: image: reponame/appname tags: [latest] compose=dev: files: [docker-compose.yml] project: '{project}' depends: [app] Which you could run with dobi dev to build the images (once) and start Compose (the equivalent of docker-compose up -d. To get interactive logs you can run dobi dev:attach.

build command should be:

docker build -t toto/test-sample .

Docker and Docker Compose, Create Dockerfiles to build images. Define complex stacks (comprising of individual containers) based on those Dockerfile images from within  In this step, we will show you how to build a custom Docker image for your application using the Dockerfile. We will create a new custom Docker image based on Ubuntu 20.04 image, for the PHP-FPM and Nginx services, then run the new container with a simple phpinfo script. First, create a new project directory and create an empty Dockerfile.

How to build a Docker Compose file, Docker-compose build, will build individual images, by going into individual service entry in docker-compose.yml. With docker images, command,  The first two services reference images in the default Docker registry. The first is a public image, and the second is private. The third image is stored in a private repository on a different registry. We should be logged in to both registries before using docker-compose for the first time. That way our credentials will be stored in our machine:

What is the difference between Dockerfile and docker-compose.yml , By not having to install docker-compose on top of a docker:latest image it can reduce the building time about 10 / 15 seconds in a cloud data center for each build. In this tutorial, we shall show you a step-by-step process of creating a Dockerfile for nodeJS application, creating Dockerignore, and docker-compose. Creating a Dockerfile, Dockerignore, and Docker Compose 1. Dockerfile. We shall create the Dockerfile inside the source directory. vim Dockerfile

What is the difference between `docker-compose build` and `docker , We create Docker images by writing a kind of script called a "Dockerfile." Dockerfiles have a relatively short list of commands at their disposal  --no-build Don't build an image, even if it's missing. --build Build images before creating containers. fig , composition , compose , docker , orchestration , cli , create

Comments
  • 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)