Dockerfile MKDIR not working (node:alpine) - docker

I am getting error when trying to create /app directory using the files below. This has worked for me in the past so I am not sure what is going wrong now:
Step 1/8 : FROM node:alpine
---> 0d8a3475dbc3
Step 2/8 : RUN MKDIR -p "/app"
---> Running in ad24819ce982
/bin/sh: MKDIR: not found
ERROR: Service 'add_delete_server' failed to build: The command '/bin/sh -c MKDIR -p "/app"' returned a non-zero code: 127
Docker compose :
version: "3.8"
services:
add_delete_server:
build:
context: ./AddDeleteServer
dockerfile: Dockerfile.dev
ports:
- "3001:3001"
volumes:
- /app/node_modules
- ./server:/app
Dockerfile.dev
FROM node:alpine
#setting work directory
RUN MKDIR -p "/app"
WORKDIR "/app"
#copying only package.json first, so cache can be used for minor changes
COPY package.json .
COPY package-lock.json .
RUN npm install
# copy rest of files
COPY . .
CMD ["npm", "run","dev"]
But I am not able to generate

MKDIR is not a command ,mkdir is the command

Related

executable not found on docker container

I'm having some issue trying to run a CMD command inside a docker container with a Go application.
This is the output I've got:
golang-api | /bin/sh: ./server: not found
golang-api exited with code 127
This is the Dockerfile
FROM golang:1.18-alpine
RUN apk add g++ && apk add make
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make build
EXPOSE 8000
CMD ./server
And this is the Makefile responsible for the build command:
LINUX_AMD64 = GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GO111MODULE=on
migrate:
cd cmd/migrations/$(FOLDER) && go run main.go
build:
cd cmd && $(LINUX_AMD64) go build -a -v -tags musl -o server
And the docker-compose.yml
version: '3.1'
services:
api:
build:
dockerfile: Dockerfile
context: .
container_name: golang-api
ports:
- "8000:8000"
restart: unless-stopped
depends_on:
- db
environment:
- POSTGRES_URL=$POSTGRES_URL
db:
image: postgres
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'
Complete output:
Building api
Sending build context to Docker daemon 74.24kB
Step 1/9 : FROM golang:1.18-alpine
---> 6078a5fce1f5
Step 2/9 : RUN apk add g++ && apk add make
---> Using cache
---> 2a85b9182b80
Step 3/9 : WORKDIR /app
---> Using cache
---> baf1e6b7047c
Step 4/9 : COPY go.mod go.sum ./
---> Using cache
---> 1f2d031bc1b0
Step 5/9 : RUN go mod download
---> Using cache
---> 471d6f24e6a9
Step 6/9 : COPY . .
---> eaa86ff7cb1b
Step 7/9 : RUN make build
---> Running in d6ae6ce79222
cd cmd && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 GO111MODULE=on go build -a -v -tags musl -o server
internal/goos
internal/goarch
internal/race
internal/unsafeheader
internal/goexperiment
runtime/internal/syscall
internal/cpu
sync/atomic
runtime/internal/atomic
internal/itoa
math/bits
internal/abi
runtime/internal/math
runtime/internal/sys
unicode/utf8
unicode
container/list
crypto/internal/subtle
crypto/subtle
unicode/utf16
vendor/golang.org/x/crypto/cryptobyte/asn1
internal/nettrace
vendor/golang.org/x/crypto/internal/subtle
encoding
github.com/mymachine/my-api/internal/controllers/dto
github.com/mymachine/my-api/internal/controllers/helpers
internal/bytealg
math
runtime
internal/reflectlite
sync
internal/testlog
internal/singleflight
math/rand
runtime/cgo
errors
sort
internal/oserror
strconv
path
vendor/golang.org/x/net/dns/dnsmessage
io
crypto/elliptic/internal/fiat
syscall
golang.org/x/text/internal/tag
hash
bytes
strings
hash/crc32
reflect
crypto
crypto/internal/randutil
crypto/hmac
crypto/rc4
net/http/internal/ascii
vendor/golang.org/x/crypto/hkdf
regexp/syntax
github.com/jackc/chunkreader/v2
bufio
crypto/elliptic/internal/nistec
internal/syscall/unix
time
internal/syscall/execenv
vendor/golang.org/x/text/transform
golang.org/x/crypto/pbkdf2
golang.org/x/text/transform
golang.org/x/text/runes
golang.org/x/text/width
regexp
internal/poll
io/fs
context
github.com/mymachine/my-api/internal/entities
github.com/jackc/pgconn/internal/ctxwatch
embed
os
github.com/jinzhu/inflection
github.com/jinzhu/now
internal/fmtsort
encoding/binary
crypto/ed25519/internal/edwards25519/field
crypto/md5
crypto/sha512
crypto/cipher
crypto/sha256
crypto/sha1
encoding/base64
fmt
internal/godebug
encoding/pem
crypto/ed25519/internal/edwards25519
path/filepath
vendor/golang.org/x/crypto/internal/poly1305
io/ioutil
internal/intern
vendor/golang.org/x/crypto/curve25519/internal/field
vendor/golang.org/x/sys/cpu
net/netip
crypto/aes
crypto/des
vendor/golang.org/x/crypto/chacha20
github.com/jackc/pgio
github.com/jackc/pgpassfile
os/exec
os/signal
net
vendor/golang.org/x/crypto/chacha20poly1305
math/big
encoding/hex
net/url
compress/flate
vendor/golang.org/x/crypto/curve25519
log
vendor/golang.org/x/text/unicode/norm
vendor/golang.org/x/text/unicode/bidi
vendor/golang.org/x/net/http2/hpack
mime
mime/quotedprintable
compress/gzip
net/http/internal
database/sql/driver
github.com/mymachine/my-api/internal/pkg/errors
encoding/json
github.com/jackc/pgservicefile
vendor/golang.org/x/text/secure/bidirule
golang.org/x/text/internal/language
database/sql
golang.org/x/text/unicode/norm
golang.org/x/text/unicode/bidi
vendor/golang.org/x/net/idna
os/user
crypto/rand
encoding/asn1
crypto/dsa
crypto/elliptic
crypto/ed25519
crypto/rsa
github.com/jackc/pgproto3/v2
golang.org/x/text/internal/language/compact
golang.org/x/text/secure/bidirule
github.com/jackc/pgx/v4/internal/sanitize
golang.org/x/text/language
go/token
vendor/golang.org/x/crypto/cryptobyte
crypto/x509/pkix
gorm.io/gorm/utils
gorm.io/gorm/logger
encoding/gob
go/scanner
golang.org/x/text/internal
github.com/joho/godotenv
crypto/ecdsa
go/ast
golang.org/x/text/cases
github.com/joho/godotenv/autoload
golang.org/x/text/secure/precis
gorm.io/gorm/clause
gorm.io/gorm/schema
gorm.io/gorm
net/textproto
vendor/golang.org/x/net/http/httpproxy
github.com/google/uuid
crypto/x509
github.com/jackc/pgtype
mime/multipart
vendor/golang.org/x/net/http/httpguts
crypto/tls
gorm.io/gorm/migrator
gorm.io/gorm/callbacks
net/http/httptrace
github.com/jackc/pgconn
net/http
github.com/jackc/pgconn/stmtcache
github.com/jackc/pgx/v4
github.com/jackc/pgx/v4/stdlib
gorm.io/driver/postgres
github.com/mymachine/my-api/internal/infrastructure/repository
github.com/mymachine/my-api/configs
github.com/mymachine/my-api/internal/services
github.com/mymachine/my-api/internal/services/transaction
github.com/mymachine/my-api/internal/controllers/handlers/health
github.com/gorilla/mux
github.com/mymachine/my-api/internal/controllers/handlers/transaction
github.com/mymachine/my-api/internal/router
github.com/mymachine/my-api/cmd
Removing intermediate container d6ae6ce79222
---> 621aa6a266de
Step 8/9 : EXPOSE 8000
---> Running in 3cbd17d32c37
Removing intermediate container 3cbd17d32c37
---> 754f71a7753e
Step 9/9 : CMD ./server
---> Running in dfcdc8cd45ce
Removing intermediate container dfcdc8cd45ce
---> 511dbf89a001
Successfully built 511dbf89a001
Successfully tagged my-api_api:latest
Creating my-api_db_1 ... done
Creating golang-api ... done
Attaching to my-api_db_1, golang-api
golang-api | /bin/sh: ./server: not found
The problem was solved.
Somehow,the RUN cd cmd command seemed not generating the file in the expected directory.
Trying with RUN go build cmd/main.go instead of using the makefile worked, as well pointed by #paltaa in the comments.

Why docker-compose build can't run command but docker build can?

My Dockerfile:
FROM node:10 AS builder
RUN npm install multi-file-swagger -g
WORKDIR /usr/src/app
COPY swagger/* ./
ARG API_HOST
ENV APP_HOST=$API_HOST
RUN sed -i 's+replace_host+'"$API_HOST"'+g' index.yaml
RUN multi-file-swagger index.yaml > index.json
FROM golang:1.12
WORKDIR /go/src/app
COPY . .
RUN go get -d -v ./...
RUN go install -v ./...
VOLUME /go/src/app
EXPOSE 8080
COPY --from=builder /usr/src/app/ swagger/
CMD ["app"]
My docker-compose.yml file:
version: '3.4'
services:
myapp:
build:
context: .
args:
- API_HOST=api.my-real-domain.com
volumes:
- ./:/go/src/app
ports:
- "8080:8080"
If run docker build only:
docker build -t myapp . --build-arg API_HOST=api.my-real-domain.com
It can run the commands:
RUN sed -i 's+replace_host+'"$API_HOST"'+g' index.yaml
RUN multi-file-swagger index.yaml > index.json
And when lunch the container, I can find the index.json exists.
But if use docker-compose build and docker-compose up, then check the index.json in container, can't find it.
you overwrite all your files in app folder by using:
volumes:
- ./:/go/src/app
you need to remove the volume section from your compose

Docker Compose build command using Cache and not picking up changed files while copying to docker

I have a docker-compose.yml file comprising of two services (both based on a DockerFile). I have build the images once (using command: docker-compose build) and they were up and running once I ran this command (docker-compose up).
I had to change the source code used for one of the services, however, when I rebuilt the images (docker-compose build), the code changes were not reflected once I ran the services (docker-compose up).
docker-compose.yml
version: '2'
services:
serviceOne:
build:
context: ./ServerOne
args:
PORT: 4000
ports:
- "4000:4000"
env_file:
- ./ServerOne/.env
environment:
- PORT=4000
serviceTwo:
build:
context: ./serviceTwo
args:
PORT: 3000
ports:
- "3000:3000"
env_file:
- ./serviceTwo/.env
environment:
- PORT=3000
- serviceOne_URL=http://serviceOne:4000/
depends_on:
- serviceOne
serviceOne/DockerFile
FROM node:8.10.0
RUN mkdir -p /app
WORKDIR /app
ADD package.json package-lock.json /app/
RUN npm install
COPY . /app/
RUN npm build
EXPOSE ${ACC_PORT}
CMD [ "npm", "start" ]
serviceTwo/DockerFile
FROM node:8.10.0
RUN mkdir -p /app
WORKDIR /app
ADD package.json package-lock.json /app/
RUN npm install
COPY . /app/
RUN npm build
EXPOSE ${ACC_PORT}
CMD [ "npm", "start" ]
Following is the output of the docker-compose when it is ran for the second time.
It is some how using the cached images again when COPY and npm build command are ran.
How could the DockerFile or docker-compose file be changed so that the new source code is deployed?
You can force the build to ignore the cache by adding on the --no-cache option to the docker-compose build

"No Go files in..." error when i use go with docker compose

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.

docker-compose error when running netcore-react app

When I build my app without using docker-compose :
docker build -t aspnetapp .
docker run -d -p 8080:80 --name myapp aspnetapp
the docker container runs just fine. But when I try to run it, using docker-compose up, the image builds successfully but the website gives me errors on loading.
dockerfile:
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash -
RUN apt-get install -y nodejs
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "app.dll"]
docker-compose:
version: '3.4'
services:
app:
image: aspnetapp
build: ./app
ports:
- "8080:80"
AggregateException: One or more errors occurred. (One or more errors occurred. (Failed to start 'npm'. To resolve this:.
[1] Ensure that 'npm' is installed and can be found in one of the PATH directories.
Current PATH enviroment variable is: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Make sure the executable is in one of those directories, or update your PATH.
removing
environment: - ASPNETCORE_ENVIRONMENT=Development
from the compose.override file fixed all this. I'm not sure why it's the problem.
Is your Dockerfile in ./ or ./app? If it's in ./ change docker-compose.yml to build: ./
EDIT
I've just realised that you are specifying both image and build in your docker-compose.yml; get rid of the image.

Resources