AWS CodePipeline environment variables not passed to Docker - amazon-web-services

In my CodeBuild step I have an environment variable called VUE_APP_BACKEND defined as a URL. I confirmed that this part is OK by adding echo $VUE_APP_BACKEND to my buildspec.yml.
That one will output
[Container] 2020/11/26 13:22:25 Running command echo $VUE_APP_BACKEND
https://my-url-here
However when I try to forward this argument into the docker build it is lost. Am I doing it incorrectly?
I have a Dockerfile that looks like this. The echo part outputs nothing.
#build stage
FROM node:12.18.2-alpine3.10 as build-stage
ARG VUE_APP_BACKEND
ENV VUE_APP_BACKEND $VUE_APP_BACKEND
RUN echo $VUE_APP_BACKEND
# Create app directory
RUN mkdir -p /app
WORKDIR /app
# Bundle app source
COPY package*.json ./
COPY .npmrc ./
RUN npm install
COPY . .
RUN npm run build
#production stage
FROM nginx:1.14.1-alpine as production-stage
COPY --from=build-stage /app/dist/spa /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD [ "nginx", "-g", "daemon off;" ]

Related

Dockerfile: COPY static Swagger no such file or directory error

Docker can't find my static Swagger files. My code is working on localhost, but when I try to run on a staging server I get the following error in AWS CodePipeline:
COPY failed: stat /var/lib/docker/overlay2/ebbaca51ed1994dce1148a3fdcdbb80dafa1f3266bad100393bbd2d27413b607/merged/app/TimeProject.Beta.Nswag/specification: no such file or directory`
My docker file:
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
ARG asmver=1.0.0.0
WORKDIR /source
COPY . .
RUN dotnet restore --configfile Application.Startup/NuGet.Config Application.Startup/Application.Startup.csproj
RUN dotnet publish -c Release -o /app Application.Startup/Application.Startup.csproj /p:AssemblyVersion=$asmver
COPY Application.Startup/cert.pfx /app/cert.pfx
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
WORKDIR /app
# https://github.com/dotnet/runtime/issues/30667 -> To be fixed in .Net 5.0
RUN sed -i "s|DEFAULT#SECLEVEL=2|DEFAULT#SECLEVEL=1|g" /etc/ssl/openssl.cnf
RUN mkdir ../TimeProject.Beta.Nswag
RUN mkdir ../TimeProject.Beta.Nswag/specification
COPY --from=build /app .
COPY --from=build /app ./
RUN pwd
RUN dir
COPY --from=build /app/TimeProject.Beta.Nswag/specification/ ../TimeProject.Beta.Nswag/specification
ENTRYPOINT ["dotnet", "Application.Startup.dll"]
CodeBuild-Docker.yaml:
version: 0.2
phases:
install:
runtime-versions:
docker: latest
dotnet: 3.1
pre_build:
commands:
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
build:
commands:
- echo $RELEASE_VERSION
- cd src/app
- docker build . -f Application.Startup/Dockerfile -t $IMAGE_REPO_NAME:$RELEASE_VERSION --build-arg asmver=$RELEASE_VERSION
- docker tag $IMAGE_REPO_NAME:$RELEASE_VERSION $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$RELEASE_VERSION
post_build:
commands:
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$RELEASE_VERSION
Solved by removing
COPY Application.Startup/cert.pfx /app/cert.pfx
and
COPY --from=build /app .
, and by adding
EXPOSE 5001

Apache Druid Nano Container Service Error

I want to spin up a low configuration containerized service for which I created a Dockerfile as below:
docker build -t apache/druid_nano:0.20.2 -f Dockerfile .
FROM ubuntu:16.04
Install Java JDK 8
RUN apt-get update
&& apt-get install -y openjdk-8-jdk
RUN mkdir /app
WORKDIR /app
COPY apache-druid-0.20.2-bin.tar.gz /app
RUN tar xvzf apache-druid-0.20.2-bin.tar.gz
WORKDIR /app/apache-druid-0.20.2
EXPOSE <PORT_NUMBERS>
ENTRYPOINT ["/bin/start/start-nano-quickstart"]
When I start the container using the command "docker run -d -p 8888:8888 apache/druid_nano:0.20.2, I get an error as below:
/bin/start-nano-quickstart: no such file or directory
I removed the ENTRYPOINT command and built the image again just to check if the file exists in the bin directory inside the container. There is a file start-nano-quickstart under the bin directory inside the container.
Am I missing anything here? Please help.

Is it mandatory to have the EXPOSE command within the Dockerfile to expose ports

Is it mandatory to have the EXPOSE command within the Dockerfile to expose ports or is it good enough to pass it in the run command itself as an argument
FROM node:8
EXPOSE 3000
WORKDIR /app
COPY package.json index.js ./
RUN npm install
CMD ["npm", "start"]

Docker error: entrypoint permission denied

I'm trying to build a docker image where the entrypoint can run without the error:
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"/app\": permission denied": unknown.
my OS: Windows 10
Dockerfile content:
ARG GO_VERSION=1.11
FROM golang:${GO_VERSION}-alpine AS builder
RUN mkdir /user && \
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
echo 'nobody:x:65534:' > /user/group
RUN apk add --no-cache ca-certificates
ENV CGO_ENABLED=0 GOFLAGS=-mod=vendor
WORKDIR $GOPATH/src/XXXXmyrepoXXXX
COPY ./ ./
RUN go build \
-installsuffix 'static' \
-o /app .
FROM scratch AS final
COPY --from=builder /user/group /user/passwd /etc/
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app /app
EXPOSE 8080
USER nobody:nobody
ENTRYPOINT ["/app"]
How should I change the Dockerfile, it should work as well as it does here https://medium.com/#pierreprinetti/the-go-1-11-dockerfile-a3218319d191? There are literally no changes.
The error was that i did not go build the correct path.

copy a file using an environment var in a docker file then execute the entrypoint

I'm trying to deploy a container and dynamically set the correct configuration (dev, qa, prod) at run time
basically I want to do this....(which doesn't work)
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
COPY dist/ .
CMD cp configuration.$env.json configuration.json
ENTRYPOINT [ "nginx", "-g", "daemon off;" ]
And then when I start the container I pass the env that I want
docker run -d -p 8080:80 --name MyUI -e env=qa myimage
Ideally I want the CMD to be a shell command, so I get the environment var and the ENTRYPOINT to be exec form (if this is possible)
Have you tried using ARG ? Also, if these are just qa, prod etc then okay but if you are planning to use secrets that way then better using env_file and encrypt it as ARG leaves traces