docker build command doesn't refresh my source files - docker

I made a typo in my source code and I noticed it after i run docker-compose up in my cli. I tried rebuilding the project but didn't change my index.js cached code.
This is my Dockerfile
FROM node:alpine
WORKDIR '/app'
COPY package.json .
RUN npm install
COPY . .
CMD [ "npm","start" ]
docker-compose.yml
version: '3'
services:
redis-server:
image: 'redis'
node-app:
build: .
ports:
- "4001:8081"
I recreated the image
$ sudo docker build -t phillalexakis/visits:latest .
and run
docker-composer up
It didn't change the source code at all, what have I completely missed? (I'm new with docker)

Docker-compose is looking for an image named [folder_name]_node-app, but the image you've built is tagged phillalexakis/visits.
Change your node-app service in docker-compose.yml file :
node-app:
build: .
image: node-app
And use docker-compose to build the images:
docker-compose build or docker-compose up --build

Related

Folder missmatch with docker compose and deploying to heroku

I have a docker-compose file which looks like this
version: '3'
services:
banana:
image: &banana_version recruiter-1912/banana:20.8.1
build:
context: platform
dockerfile: banana/Dockerfile
ports:
- "8000:8000"
environment:
PORT: 8000
MN_VERSION: *banana_version
volumes:
- ./platform/banana:/banana
With this file structure:
- platform/
- banana/
- Dockerfile
- requirements.txt
- banana/
-seemingly unimportant files-
- docker-compose.yml
And i am trying to deploy this service to Heroku.
I do this by doing heroku container:push web but for that i cd into the platform/banana directory.
When i try to push the container i get an error
COPY failed: stat /var/lib/docker/tmp/docker-builder648546726/banana/requirements.txt: no such file or directory
FROM python:3.7.7-slim
COPY banana/requirements.txt .
RUN pip install -r requirements.txt
ADD . /banana
WORKDIR /banana
CMD gunicorn -b :$PORT -k uvicorn.workers.UvicornWorker banana.main:app
I can deploy this to heroku if i change COPY banana/requirements.txt . to COPY requirements.txt . BUT then my docker-compose build will not work due to the same no such file or directory error.
How do i make it so i can both deploy to heroku and docker-compose build locally without needing to change the file path in dockerfile every time?
Try to change the context to ., like this:
context: .
It means your context is the current working directory.
and change
COPY banana/requirements.txt .
to
COPY platform/banana/requirements.txt .

docker-compose failed to run the container

I am using this docker-compose.yml file to build an image.
Problem is when I don't use the docker-compose.yml instead use the usual docker build command, it works fine. But when I use the same Dockerfile to build the using the docker-compose it doesn't work.
This is my Dockerfile
# Use an official node runtime as a parent image
FROM node:8
WORKDIR /app/
# Install dependencies
COPY package.json /app/
RUN npm install
# Add rest of the client code
COPY . /app/
EXPOSE 3000
CMD npm start
and this is my docker-compose.yml
version: "3.2"
services:
frontend:
build: ./my-app
ports:
- 80:3000
command: npm start
Container exited right after it creates when using the docker-compose
Can someone please help me?
[Update]
This is the error I am getting

Docker container port is not made public

docker-compose.yml
version: '3.3'
services:
apps:
build:
context: .
dockerfile: ./Dockerfile
ports:
- "3000:3000"
restart: always
Dockerfile
FROM node:latest
RUN mkdir -p /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
EXPOSE 3000
RUN npm install
RUN npm start
Only port expose is seen here but the internal port 3000 is not made public
Versions:
Docker version 18.09.2, build 6247962
docker-compose version 1.23.2, build 1110ad01
I don't get it! You used docker-compose and created apps service, but your container has a random name crancky villani!!!
go into the path your docker-compose.yml placed and run this command:
docker-compose down; docker-compose up -d --build
Then check the results again.
Docker image was not properly built since the last step to start node is defined incorrectly.
it is supposed to be like this,
CMD ["npm", "start"]

Binary isn't persisted in dockerfile

Newbie to Docker and what appears to be a simple issue isn't working. I would like to build a binary inside of a dockerfile and execute the binary in docker-compose.
Dockerfile:
FROM golang:1.10
ENV DIR=/go/src/api
RUN go get github.com/Masterminds/glide
WORKDIR $DIR
ADD glide.yaml glide.yaml
ADD glide.lock glide.lock
RUN glide install
COPY . $DIR
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
CMD main
And in my docker-compose.yml I have this:
version: '2'
services:
api:
build:
context: ./api
dockerfile: Dockerfile
ports:
- 8000:8000
However, there's no main executable when run from docker-compose. I've actually added a command: ls to the docker-compose file and it's not there. I've then added a ls to the Dockerfile image and main is there.
How do I prevent main from being lost in translation?

Asp.net core with linux docker container

For a asp.net core project template in VS 2017, there are docker-compose.ci.build.yml:
version: '3'
services:
ci-build:
image: microsoft/aspnetcore-build:1.0-2.0
volumes:
- .:/src
working_dir: /src
command: /bin/bash -c "dotnet restore ./WebAppCoreDockerTest.sln && dotnet publish ./WebAppCoreDockerTest.sln -c Release -o ./obj/Docker/publish"
docker-compose.yml:
version: '3'
services:
webappcoredockertest:
image: webappcoredockertest
ports:
- 8080:80
build:
context: ./WebAppCoreDockerTest
dockerfile: Dockerfile
and Dockerfile:
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 80
RUN echo "Oh dang look at that $source"
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "WebAppCoreDockerTest.dll"]
The Dockerfile uses the files in obj/Docker/publish (copied to container) if source argument is null and docker-compose.ci.build.yml puhlishs project to obj/Docker/publish, I assume they are related.
So the question is How to use them together? (docker-compose.ci.build.yml publishes files to obj/Docker/publish and Dockerfile use published files)
The docker-compose.ci.build.yml file is for building the project, as you mentioned. It uses the aspnetcore-build base image which is much heftier than the aspnetcore image used by the Dockerfile. The Dockerfile gets used by the build section of the docker-compose.yml file.
Everything works together with these two steps:
docker-compose -f docker-compose.ci.build.yml run ci-build
docker-compose up --build
The -f option in the first command allows you to specify a compose file other than the default docker-compose.yml.

Resources