I would like to create a dockerfile which will allow me to use gcc compiler into container. Currently I am using dockerfile generated by VS for my asp net core project.
My dockerfile:
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 55712
EXPOSE 44396
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["Eunomia.API/Eunomia.API.csproj", "Eunomia.API/"]
COPY ["Eunomia.Insfrastrucutre/Eunomia.Infrastrucutre.csproj", "Eunomia.Insfrastrucutre/"]
COPY ["Eunomia.Core/Eunomia.Core.csproj", "Eunomia.Core/"]
RUN dotnet restore "Eunomia.API/Eunomia.API.csproj"
COPY . .
WORKDIR "/src/Eunomia.API"
RUN dotnet build "Eunomia.API.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "Eunomia.API.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Eunomia.API.dll"]
I was trying solution like this:
FROM gcc:4.9
COPY . /usr/src/compiler_cpp
WORKDIR /usr/src/compiler_cpp
RUN apt-get update && \
apt-get -y install gcc mono-mcs && \
rm -rf /var/lib/apt/lists/*
To add gcc, but that didn't help me still I couldn't reach gcc from container bash.
Why I need this?
I need this, becouse I am writing a dot net core web API which allow to check if code writed in c++ is correct by using unit tests.
In advice thanks for help :)
Related
Im going crazy here... im trying to create a docker container with this file:
#Docker
FROM golang:alpine as builder
RUN apk update && apk add --no-cache git make gcc libc-dev
# download, cache and install deps
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
# copy and compiled the app
COPY . .
RUN make ditto
# start a new stage from scratch
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# copy the prebuilt binary from the builder stage
COPY --from=builder /app/_build/ditto .
COPY --from=builder /app/send-email-report.sh /usr/bin/
ENTRYPOINT ["./ditto"]
Running: docker build .
On my Pc it works perfect
BUT in my AWS instance of EC2 same code:
docker build .
Sending build context to Docker daemon 108kB
Step 1/13 : FROM golang:1.18-alpine as builder
---> 155ead2e66ca
Step 2/13 : RUN apk update && apk add --no-cache git make gcc libc-dev
---> Running in 1d3adab601f3
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
v3.16.0-99-g5b6c75ce95 [https://dl-cdn.alpinelinux.org/alpine/v3.16/main]
v3.16.0-108-ge392af4f2e [https://dl-cdn.alpinelinux.org/alpine/v3.16/community]
OK: 17022 distinct packages available
And get Stuck there...
It was working fine in the past, I think nobody has change on that docker file and folder...
Can somebody help me? please
I need to read in my application from a file "cert.pem" whose path is a) provided as an argument or b) it is retrieved from the directory of the main application file main.py.
I have created the following dockerfile, but after building and running my application using the image the "cert.pem" file cannot be accessed. Is there a way to read from this file?
FROM golang:1.17-alpine AS builder
RUN apk add --no-cache git
WORKDIR /app
COPY . .
RUN go mod download
RUN go build -o ./bin .
#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /app/bin /app/bin
EXPOSE 3000
CMD ["/app/bin"]
The instruction to load the file is the following:
....
var (
cert_file = flag.String("cert", "./cert.pem", "File name of x509 certificate")
)
...
func main() {
...
_, err := ioutil.ReadFile(*cert_file)
...
you just have to copy your cert.pem file to the location of the binary in the final stage in docker. Assuming you have the cert file in your docker build context, you run a copy command.
FROM golang:1.17-alpine AS builder
RUN apk add --no-cache git
WORKDIR /app
COPY . .
RUN go mod download
RUN go build -o ./bin .
#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /app/bin /app/bin
COPY cert.pem /app/
EXPOSE 3000
CMD ["/app/bin"]
Make sure you set the cert.pem location in your go program as ./cert.pem
The solution is to define an ENTRYPOINT instead CMD and add a WORKDIR instruction:
#build stage
FROM golang:1.17-alpine AS builder
RUN apk add --no-cache git
WORKDIR /app
COPY . .
RUN go mod download
RUN go build -o ./bin .
#final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder /app/bin /app/bin
COPY --from=builder /app/cert.pem /app/cert.pem
EXPOSE 3000
WORKDIR /app
ENTRYPOINT ["/app/bin"]
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.
I'm using Jason Taylor's Clean Architecture template and I wonder why his WebUI Dockerfile is generated by Visual Studio just like below.
It sets WORKDIR to /src and then copies each project from /src/ProjectDir/Project.csproj. What's the point of WORKDIR in that case? Look at WORKDIR "/src/src/WebUI". Why /src/src? There is only one src directory.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt install -y nodejs
WORKDIR /src
COPY ["src/WebUI/WebUI.csproj", "src/WebUI/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CleanArchitecture.WebUI.dll"]
I suspect this is because WORKDIR /src will create a directory called /src AND change directories into it. After changing into it, it will copy files from the host's relative src folder and into another subdirectory called src (on the container). So the full absolute path becomes /src/src. You can confirm this by adding RUN pwd && ls before the WORKDIR and after the first COPY.
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
ENV ASPNETCORE_URLS=https://+:5001;http://+:5000
WORKDIR /app
EXPOSE 5000
EXPOSE 5001
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN apt install -y nodejs
RUN pwd && ls /
WORKDIR /src
COPY ["src/WebUI/WebUI.csproj", "src/WebUI/"]
RUN pwd && ls
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure/Infrastructure.csproj", "src/Infrastructure/"]
RUN dotnet restore "src/WebUI/WebUI.csproj"
COPY . .
WORKDIR "/src/src/WebUI"
RUN dotnet build "WebUI.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebUI.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CleanArchitecture.WebUI.dll"]
i have the next problem:
i try to build a docker image with ros2, in which a code package is downloaded which will be built using the colcon build method.
but when I try to run last of. install / setup.bash doesn't work for me.
I already tried to put it in a script and copy it to the dockerfile but it didn't work
any ideas
here I leave the docker file
FROM osrf/ros:dashing-desktop
WORKDIR /home
COPY mobilidad.sh .
RUN bash mobilidad.sh
ENV ROS2_WS cleanmyway/test_ws
RUN mkdir -p ${ROS2_WS}/src/demo_py
COPY ./ ${ROS2_WS}/src/demo_py
WORKDIR ${ROS2_WS}
SHELL ["/bin/bash", "-c"]
RUN colcon build
RUN . install/setup.bash
note: mobilidad.sh is a script that dowload de code from github, this works fine
I think I managed to find a solution,
building the dockerfile as follows:
FROM osrf/ros:dashing-desktop
WORKDIR /home
COPY mobilidad.sh .
RUN bash mobilidad.sh
ENV ROS2_WS cleanmyway/test_ws
RUN mkdir -p ${ROS2_WS}
WORKDIR ${ROS2_WS}
RUN colcon build
RUN echo "source install/setup.bash" >> /opt/ros/dashing/setup.bash
and when i run the ros2 command works fine
but anyway thanks for the help. :)
note: i'm not sure if the better form but works for me