I used docker-compose for setting on my local machine.
Vapor app is working fine without using docker.
Environment
MacBook M1 Pro 14inch 2021
32GB Ram
But I got an error at Step 3
(Step 1, and 2 are ok, Swift compiler builds Vapor app successfully)
Received signal 4. Backtrace:
#!/bin/bash
echo "Step 1: Build Docker"
docker-compose -f local-docker-compose.yml build
echo "Step 2: Start dependencies"
docker-compose -f local-docker-compose.yml run --rm
echo "Step 3: Start Vapor App"
docker-compose -f local-docker-compose.yml up myapp-beta
# Build image
FROM --platform=linux/x86-64 swift:5.5-focal as build
RUN apt-get update -y \
&& apt-get install -y libsqlite3-dev
WORKDIR /build
COPY . .
RUN swift build \
--enable-test-discovery \
-c release \
-Xswiftc -g
# Run image
FROM --platform=linux/x86-64 swift:5.5-focal-slim
RUN useradd --user-group --create-home --home-dir /app vapor
WORKDIR /app
COPY --from=build --chown=vapor:vapor /build/.build/release /app
COPY --from=build --chown=vapor:vapor /build/Public /app/Public
# ARS RDS Environment ARG
ARG AWS_RDS_HOST
ARG AWS_RDS_PORT
ARG AWS_RDS_USER
ARG AWS_RDS_PASS
ARG AWS_RDS_DB
# SignInWithApple Environment ARG
ARG SIWA_ID
ARG SIWA_REDIRECT_URL
ARG SIWA_JWK_ID
ARG SIWA_PRIVATE_KEY
ARG SIWA_TEAM_ID
ARG SIWA_APP_BUNDLE_ID
# Set Environment
RUN echo "SIWA_ID=${SIWA_ID}" > .env.testing
RUN echo "SIWA_REDIRECT_URL=${SIWA_REDIRECT_URL}" >> .env.testing
RUN echo "SIWA_JWK_ID=${SIWA_JWK_ID}" >> .env.testing
RUN echo "SIWA_PRIVATE_KEY=${SIWA_PRIVATE_KEY}" >> .env.testing
RUN echo "SIWA_TEAM_ID=${SIWA_TEAM_ID}" >> .env.testing
RUN echo "SIWA_APP_BUNDLE_ID=${SIWA_APP_BUNDLE_ID}" >> .env.testing
RUN echo "DB_HOST=${AWS_RDS_HOST}" >> .env.testing
RUN echo "DB_PORT=${AWS_RDS_PORT}" >> .env.testing
RUN echo "DB_USER=${AWS_RDS_USER}" >> .env.testing
RUN echo "DB_PASS=${AWS_RDS_PASS}" >> .env.testing
RUN echo "DB_NAME=${AWS_RDS_DB}" >> .env.testing
USER vapor
EXPOSE 8080
ENTRYPOINT ["./Run"]
CMD ["serve", "--env", "local", "--hostname", "0.0.0.0", "--port", "8080"]
version: '3.7'
services:
myapp-beta:
depends_on:
- postgres
build:
context: .
args:
AWS_RDS_HOST: postgres
AWS_RDS_PORT: 5432
AWS_RDS_USER: test
AWS_RDS_PASS: test1228!1
AWS_RDS_DB: myapp_db
SIWA_ID: com.beta.myapp.service
SIWA_REDIRECT_URL: localhost:8080
SIWA_JWK_ID: JLJKLXXXX
SIWA_PRIVATE_KEY: xxxxxxx
SIWA_TEAM_ID: 9DFSXXXX
SIWA_APP_BUNDLE_ID: com.beta.myapp
dockerfile: local.Dockerfile
ports:
- '8080:8080'
postgres:
image: postgres
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test1228!1
POSTGRES_DB: myapp_db
start_dependencies:
image: dadarek/wait-for-dependencies
depends_on:
- postgres
command: postgres:5432
focal now includes arm64 arch that is necessary to run on M1. Here is the manifest:
docker manifest inspect swift:5.6-focal
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.list.v2+json",
"manifests": [
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 1162,
"digest": "sha256:a34fb87d14544c49d5aa30c90fcf18347d301e7db1b1e917b23796d687c3e178",
"platform": {
"architecture": "amd64",
"os": "linux"
}
},
{
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"size": 1162,
"digest": "sha256:3708d167c44e62c928356c1aac9ba27ab77c7a4970d32dc8126a58ca5e2c0520",
"platform": {
"architecture": "arm64",
"os": "linux",
"variant": "v8"
}
}
]
}
You Dockerfile just needs to start with:
FROM swift:focal
Related
I have a simple Dockerfile
FROM node:12.13-alpine As development
WORKDIR /usr/src/app
COPY package*.json ./
RUN apk add --no-cache bash && npm install --only=development
COPY . .
RUN npm run build
FROM node:12.13-alpine as production
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --only=production
COPY . .
COPY --from=development /usr/src/app/dist ./dist
CMD ["node", "dist/main"]
my docker-compose is:
version: '3.7'
services:
main:
container_name: main
build:
context: .
target: development
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- ${SERVER_PORT}:${SERVER_PORT}
- 9229:9229
command: npm run start:debug
env_file:
- .env
Inside my package.json and script, I have:
"start:debug": "nest start --debug 0.0.0.0:9229 --watch"
I added the conf in my visual Studio Code (.vscode/launch.json)
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Debug",
"address": "127.0.0.1",
"port": 9229,
"sourceMaps": true,
"restart": true,
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/app",
"skipFiles": ["<node_internals>/**"]
}
]
}
After that I can run docker-compose up --build and start my debugger but the code doesn't stop at my breakpoint.
I use Mac 12.6 and Docker version 20.10.13
I have tried every combination I can think of.
docker-compose.yml
version: "3.1"
services:
node-server:
build:
context: .
dockerfile: Dockerfile
args:
- MYVAR=${MYVAR}
environment:
- ENV_MYVAR=${MYVAR}
ports:
- 8000:8000
env_file:
- .env
# command: ["npm", "run", "_${MYVAR}_"] This works, but for the sake of testing CMD in Dockerfile, I can't get that to work
Dockerfile
FROM node:14
ARG MYVAR
ENV ENV_MYVAR="${MYVAR}"
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm i
COPY . .
EXPOSE ${port}
RUN echo "1"
RUN echo $MYVAR # Works
CMD [ "npm", "run", "_${ENV_MYVAR}_"] # OUTPUTS as _${ENV_MYVAR}_". Does not interpolate!!
.env
MYVAR=boot
package.json
{
"name": "node-server-ts",
"version": "1.0.0",
"license": "MIT",
"scripts": {
"test": "echo 'test'",
"boot": "echo 'boot'",
"_boot_": "echo '_boot_'"
}
}
terminal
docker-compose up
Expect:
npm run _boot_
error - node-server_1 | ${ENV_MYVAR}
Try removing the square brackets.
CMD npm run "_${ENV_MYVAR}_"
See this StackOverflow question about the differences
I have a .Net 5 WebApi that i want to host and debug in Docker.
when i run the docker-compose the project launches correctly.
When attaching the debugger i get following error:
Running the contributed command csharp.listRemoteProcess failed
my docker file:
FROM mcr.microsoft.com/dotnet/sdk:5.0 as debug
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
ENV ASPNETCORE_URLS=http://+:5000
EXPOSE 5000/tcp
WORKDIR /app
COPY . /app
RUN apt-get update
RUN apt-get install -y unzip
RUN curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l ~/vsdbg
ENTRYPOINT ["dotnet", "watch", "run", "--project myproject.csproj"]
the docker-compose file
version: '3.4'
services:
server:
build:
context: ./myproject
target: debug
ports:
- "5000:5000"
container_name: myproject
volumes:
- ./myproject:/app
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Docker Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"pipeProgram": "docker",
"pipeArgs": [ "exec", "-i", "csharp" ],
"debuggerPath": "/root/vsdbg/vsdbg",
"pipeCwd": "${workspaceRoot}",
"quoteArgs": false
},
"sourceFileMap": {
"/work": "${workspaceRoot}/myproject/"
}
}
]
}
My Dockerfile is
FROM keymetrics/pm2:latest-alpine
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
RUN npm install prpl-server
COPY build build/
COPY package.json .
COPY polymer.json .
COPY --chown=node:node . .
USER node
EXPOSE 8080
RUN ls -al -R
CMD [ "pm2-runtime", "start", "ecosystem.config.js", "--web"]
and my ecosystem.comfig.js is
module.exports = {
apps: [{
name: 'ozark',
script: 'npm',
args: 'start',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: "development",
},
env_production: {
NODE_ENV: "production",
}
}],
};
and the start script inside package.json is
"start": "cd build && prpl-server --root . --config polymer.json --port 8080 && cd ../",
to build the container im doing
polymer build && docker build -t ozark .
to start the container i do
docker run --name ozark -p 80:8080 -d ozark
but when I browse to http://locallhost nothing loads and I dont understand why.
I have viewed the logs from inside the container and the prpl server is running on port 8080
docker ps gives me...
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e7f633881e17 ozark "pm2-runtime start e…" 11 minutes ago Up 11 minutes 80/tcp, 443/tcp, 43554/tcp, 0.0.0.0:80->8080/tcp ozark
I am building an app with Go and Glide in docker. I also have to use reflex to trigger the compiling automatically.
I can not figure out how to make Glide work out with docker.
Dockerfile
FROM golang:1.8.1-alpine
ENV GOBINARIES /go/bin
ENV BUILDPATH /code
ENV REFLEXURL=http://s3.amazonaws.com/wbm-raff/bin/reflex1.8a
ENV REFLEXSHA=19bdbbb68c869f85ee22a6b7fa9c73f8e5b46d0fe7a73df37e028555a6ba03e8
WORKDIR $GOBINARIES
RUN rm -rf /var/cache/apk/*
RUN wget -q "$REFLEXURL" -O reflex
RUN chmod +x /go/bin/reflex
ENV TOOLS /go/_tools
RUN mkdir -p $BUILDPATH
ENV PORT 5000
EXPOSE $PORT
RUN mkdir -p $TOOLS
ADD build.sh $TOOLS
ADD reflex.conf $TOOLS
RUN chown root $TOOLS/build.sh
RUN chmod +x $TOOLS/build.sh
WORKDIR $BUILDPATH
CMD ["reflex","-c","/go/_tools/reflex.conf"]
build.sh
set -e
echo "[build.sh:building binary]"
cd $BUILDPATH
glide install -s -v
go build -o /servicebin && rm -rf /tmp/*
echo "[build.sh:launching binary]"
/servicebin
reflex.conf
-sr '\.build$' -- sh -c '/go/_tools/build.sh'
docker-compose.yaml
version: '3'
services:
logen:
build:
context: ./Docker
dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- .:/code
Atom on-save plugin configuration file
[
{
"srcDir": ".",
"destDir": ".",
"files": "**/*.go",
"command": "echo $(date) - ${srcFile} > .build"
}
]
main.go
package main
import (
"io"
"log"
"net/http"
"os"
"github.com/astaxie/beego"
)
func hello(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, "Hello world!1")
}
func main() {
log.SetOutput(os.Stdout)
port := ":" + os.Getenv("PORT")
http.HandleFunc("/", hello)
log.Printf("\n Application is listening on %v\n", port)
http.ListenAndServe(port, nil)
}
Actually, I do not need to install Glide in the container! Just reflect the vendor folder in host machine to $GOPATH/src in docker-compose.yml. Then the compile will be ok.
version: '3'
services:
logen:
build:
context: ./Docker
dockerfile: Dockerfile
ports:
- "5000:5000"
volumes:
- .:/code
- ./vendor:/go/src