I am trying to build a docker image on Windows 10 to deploy on an Ubuntu server, and I am getting the error in the title upon running it.
Here is my Dockerfile:
# first build stage to download code repos
FROM ubuntu as intermediate
# enable root ssh
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
# install git
RUN apt-get update
RUN apt-get install -y git
# save git ssh private key
ADD id_rsa /root/.ssh/id_rsa
ADD config /root/.ssh/config
RUN chmod 600 /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/config
# make sure bitbucket.org is accepted
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
# clone code repositories
RUN git clone --single-branch --branch production git@bitbucket.org:webfootdesigns/dtms-api-service.git
RUN git clone --single-branch --branch production git@bitbucket.org:webfootdesigns/dtms-cache-service.git
RUN git clone --single-branch --branch production git@bitbucket.org:webfootdesigns/dtms-express.git
RUN git clone --single-branch --branch production git@bitbucket.org:webfootdesigns/dtms-client.git
FROM ubuntu
# copy repositories from intermediate
COPY --from=intermediate /dtms-api-service /srv/dtms-api-service
COPY --from=intermediate /dtms-cache-service /srv/dtms-cache-service
COPY --from=intermediate /dtms-express /srv/dtms-express
COPY --from=intermediate /dtms-client /srv/dtms-client
# install nodejs, npm, and git
RUN apt update -y
RUN apt install nodejs npm git -y
# update nodejs and npm
RUN npm cache clean -f
RUN npm install npm@latest -g
RUN npm install -g n
# install required global npm packages
RUN npm install -g pm2 webpack
# load environment variables
ADD env.sh /env.sh
RUN chmod +x /env.sh
RUN chmod 700 /env.sh
# convert CRLF to LF
RUN awk '{ sub("\r$", ""); print }' ./env.sh > ./env.sh
RUN ./env.sh
RUN rm /env.sh
# install dependencies
RUN cd /srv/dtms-api-service && npm install
RUN cd /srv/dtms-cache-service && npm install
RUN cd /srv/dtms-express && npm install
RUN cd /srv/dtms-client && npm install
# build and copy client
RUN cd /srv/dtms-client && npm run build
RUN yes | cp -rf /srv/dtms-client/build/* /srv/dtms-express/public
# expose ports
EXPOSE 3001
# ENTRY: add and run the start script
ADD start.sh /
# convert CRLF to LF
RUN awk '{ sub("\r$", ""); print }' /start.sh > /start.sh
RUN chmod +x /start.sh
ENTRYPOINT ["./start.sh"]
start.sh:
#!/bin/bash
cd /srv/dtms-api-service &&
pm2 start npm -- start --name dtms-api-serivce &&
pm2 /srv/dtms-cache-service/app.js --name dtms-cache-service &&
pm2 /srv/dtms-express/app.js --name dtms-express
Build procedure:
local machine:
> docker build -t dtms-reporting .
> docker tag dtms-reporting my.container.registry/dtms-reporting
> docker push my.container.registry/dtms-reporting
server:
> docker pull my.container.registry/dtms-reporting:latest
> docker run -p 3001:3001 my.container.registry/dtms-reporting
Then I receive the error: standard_init_linux.go:207: exec user process caused "exec format error"
.
Edit: I figured it may have something to do with building on Windows and deploying on Ubuntu. So I tried building on the server, then tried building on my local machine with WSL, and both give the exact same result.