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.
Related
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
I installed Go on Ubuntu 16.04. This is my GOPATH=/home/{username}/work.
I created a project into /home/{username}/work/src.
This is my project folder hierarchy.
project-name
services
configuration
api
main.go
Dockerfile
bff
api
main.go
Dockerfile
docker-compose.yml
favicon.ico
README.md
I can build and run with my dockerfile but I can't build and up with docker-compose.
I couldn't find any solution.
Configuration service dockerfile:
FROM golang:1.11.1-alpine3.8 as builder
RUN apk update && apk add git && go get gopkg.in/natefinch/lumberjack.v2
RUN mkdir -p /go/src/project-name/services/configuration
RUN CGO_ENABLED=0
RUN GOOS=linux
ADD . /go/src/project-name/services/configuration
ENV GOPATH /go
WORKDIR /go/src/project-name/services/configuration/api
RUN go get
RUN go build
FROM alpine
RUN apk update
RUN apk add curl
RUN mkdir -p /app
COPY --from=builder /go/src/project-name/services/configuration/api/ /app/
RUN chmod +x /app/api
WORKDIR /app
EXPOSE 5001
ENTRYPOINT ["/app/api"]
It works with dockerfile.
This is my docker-compose file:
version: '3.4'
services:
bff:
image: project-name/bff:${TAG:-latest}
build:
context: .
dockerfile: services/bff/Dockerfile
ports:
- "5000:5000"
container_name: bff
depends_on:
- configuration
configuration:
image: project-name/configuration:${TAG:-latest}
build:
context: .
dockerfile: services/configuration/Dockerfile
ports:
- "5001:5001"
container_name: configuration
It didn't work.
When the “run go get” command runs, it gives an error, the error is:
can't load package: package project-name/services/configuration/api: no Go files in /go/src/project-name/services/configuration/api
ERROR: Service 'configuration' failed to build: The command '/bin/sh -c go get' returned a non-zero code: 1
In your Dockerfile, you say
ADD . /go/src/project-name/services/configuration
which expects the build context directory on the host to contain the source files. But your docker-compose.yml file says
build:
context: .
dockerfile: services/configuration/Dockerfile
where the context directory is the root of your source control tree, not the specific Go source directory you're trying to build. If you change this to
build:
context: services/configuration
# Default value of "dockerfile: Dockerfile" will be right
it will likely work better.
In plain Docker commands, your current docker-compose.yml file says the equivalent of
cd $GOPATH/src/project-name
docker build -f services/configuration/Dockerfile .
But you're probably actually running
cd $GOPATH/src/project-name/services/configuration
docker build .
and what directory is the current directory matters.
I have a docker setup that does not have the Dockerfile or docker-compose at the root because there are many services.
build
client.Dockerfile
deployments
docker-compose.yml
web
core
scripts
run.sh
docker-compose
version: "3.1"
services:
client:
build:
context: ..
dockerfile: ./build/client.Dockerfile
volumes:
- ./web/core:/app
ports:
- 3000:3000
- 35729:35729
And then the dockerfile:
FROM node:10.11
ADD web/core/yarn.lock /yarn.lock
ADD web/core/package.json /package.json
ENV NODE_PATH=/node_modules
ENV PATH=$PATH:/node_modules/.bin
RUN yarn
WORKDIR /app
ADD web/core /app
EXPOSE 3000
EXPOSE 35729
RUN cat /app/scripts/run.sh
ENTRYPOINT ["/bin/bash", "/app/scripts/run.sh"]
CMD ["start"]
Now the RUN command displays the result of the file so it is there. However, when running docker-compose up the client_1 | /bin/bash: /app/scripts/run.sh: No such file or directory
I'm guessing it has something to do with the docker-compose context because when the dockerfile was at the root, it seemed to work fine.
I'm getting the feeling that docker is designed essentially to work only at the root.
Context:
I want a live reloading create-react-app server like this: https://www.peterbe.com/plog/how-to-create-react-app-with-docker.
I would like to setup my project this way: https://github.com/golang-standards/project-layout
Your volume is wrongly mounting. This should fix the issue. I created the similar folder structure. From the root folder of build ran docker-compose -f ./deployments/docker-compose.yml up. It works normally only thing i change volume path.
volumes:
- ../web/core:/app
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?
It appears RUN in a dockerfile can't see my volume directory where ENTRYPOINT can.
Here is an example with a dockerfile and docker-compose.yml that is having the issue:
FROM microsoft/dotnet:2.0-sdk
EXPOSE 5000
ENV ASPNETCORE_ENVIRONMENT=Development
WORKDIR /src/testing
RUN dotnet restore
ENTRYPOINT ["dotnet", "run", "--urls=http://0.0.0.0:5000"]
docker-compose.yml:
version: "3.4"
services:
doctnetcore-api-project:
build: ./api/
container_name: doctnetcore-api-project
image: doctnetcore-api-project:development
restart: 'always'
networks:
- mynetwork
volumes:
- /api/src:/src
networks:
mywebmc:
external:
name: mynetwork
When I run docker-compose up I get an error shown below:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
ERROR: Service 'doctnetcore-api-project' failed to build: The command '/bin/sh -c dotnet restore' returned a non-zero code: 1
If I comment out RUN dotnet restore and run dotnet restore manually before running docker-compose, it works fine.
So for whatever reason it appears RUN can't see my volume directory and ENTRYPOINT can see my volume directory.
The statements in a Dockerfile are executed at build-time (docker build) and at this point there are no volumes present.
In contrast, the ENTRYPOINT is executed when you run a container (docker run) which has access to potentially mapped volumes.