I am trying to dockerize my app as part of travis ci so i can then publish it to docker hub:
I have set up my Dockerfile, docker-compose and travis.yml
when the pipeline in github finishes i get this error message:
0.60s$ docker run mysite /bin/sh -c "cd /root/mysite; bundle exec rake test"
/bin/sh: 1: cd: can't cd to /root/mysite
/bin/sh: 1: bundle: not found
The command "docker run mysite /bin/sh -c "cd /root/mysite; bundle exec rake test"" failed and exited with 127 during .
My Dockerfile:
#Server
FROM node:latest
#create app dir in the container
RUN mkdir -p /usr/src/app
#sets working direcotry for the app
#this allows to run all the comand
#like RUN CMD etc.
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm config set strict-ssl false
RUN npm install
# Bundle app source
COPY . .
EXPOSE 3006
CMD [ "npm", "run", "start:unsafe" ]
Docker-compose:
version: '3'
services:
web:
build: .
travis.yml:
sudo: required
language: node_js
node_js:
- "stable"
services:
- docker
before_install:
- docker build -t mysite .
- docker run -d -p 127.0.0.1:80:4567 mysite /bin/sh -c "cd /root/mysite; bundle exec foreman start;"
- docker ps -a
- docker run mysite /bin/sh -c "cd /root/mysite; bundle exec rake test"
cache:
directories:
- node_modules
script:
- bundle exec rake test
- npm test
- npm run build
I have tried running the comands from travis yml locally and get the same error:
/bin/sh: 1: cd: can't cd to /usr/src/app/mysite
/bin/sh: 1: bundle: not found
I tried going into the container to see if they directories are matching but the container always exits right after it starts
to execute a command on an existing running container you must call 'docker exec' and not 'docker run'
You possible mixed up node_js and ruby. Rewrite your .travis.yml to something like:
sudo: required
language: node_js
node_js:
- "stable"
cache:
directories:
- "node_modules"
services:
- docker
before_install:
- docker build -t mysite:travis-$TRAVIS_BUILD_NUMBER .
script:
- npm test
- npm run build
- docker images "$DOCKER_USERNAME"/mysite
after_success:
- if [ "$TRAVIS_BRANCH" == "master" ]; then
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD";
docker tag mysite:travis-$TRAVIS_BUILD_NUMBER "$DOCKER_USERNAME"/mysite:travis-$TRAVIS_BUILD_NUMBER;
docker push "$DOCKER_USERNAME"/mysite:travis-$TRAVIS_BUILD_NUMBER;
fi
Related
GitLab Pipeline Output
GitLab CI/CD YML file
image: docker:latest
services:
- docker:dind
stages:
- test
test_stage:
stage: test
tags:
- def
before_script:
- apk version
- apk add --no-cache docker-compose
- docker info
- docker-compose --version
script:
- echo "Building and testing"
- docker-compose up --abort-on-container-exit
Dockerfile
FROM node:10.15.3 as source
COPY package.json ./
COPY package-lock.json ./
RUN node -v
RUN npm -v
RUN npm install
COPY . ./
RUN npm run build
FROM nginx:1.15.9
COPY default.template /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
'npm run build' from the Dockerfile runs 'webpack --mode production' which attempts to start my app on localhost within Docker. Instead, GitLab is getting stuck in 'npm run build'.
This works locally with Docker but not on the GitLab CI/CD runner, it seems to be hanging there and potentially having an out of memory error, which I received earlier when it was hanging even longer.
Why is the GitLab runner getting stuck on 'webpack --mode production' (my npm run build command)? Should I only be using 'webpack -p"?
This is a docker, docker-compose and django project.
Locally, it works when I run
docker-compose build
docker-compose run --rm app sh -c "python manage.py test"
However, it failed when I run
circleci local execute
The error I get is
docker-compose build
ERROR: Couldn't connect to Docker daemon at http+docker://localhost - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
Error:
Exited with code exit status 1
Here's the .circleci/config.yml.
version: 2
jobs:
build:
docker:
- image: circleci/python:3.8.5
working_directory: ~/app
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
command: |
docker-compose build
- run:
command: |
docker-compose run --rm app sh -c "python manage.py test"
I was using travisci and it just works with the .travis.yml config file below:
language: python
python:
- "3.8"
services:
- docker
before_script: pip install docker-compose
script:
- docker-compose run app sh -c "python manage.py test"
Would appreciate some pointers here. Thank you.
I'm setting up travis to push images to docker hub after running a test script
sudo: required
services:
- docker
before_install:
- docker build -t oskygh/react-test -f ./client/Dockerfile.dev ./client
script:
- docker run oskygh/react-test npm test -- --coverage
after_success:
- docker build -t osbee/client ./client
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- docker push osbee/client
dockerfile.dev
FROM node:alpine
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm","run","start"]
As explained here you could use the travis_wait function. Adding it before the command, which failed. You could also read this stackoverflow, which added it in another way.
So the situation is that I have coupled a bash script with docker. I use bash script to pull my code from the remote repo, and then execute the docker-compose
Here's my dockerfile
FROM node:6
WORKDIR /home/ayush/project-folder
RUN pwd
RUN npm run build
CMD ["forever", "server/app.js"]
Here's the section of my docker-compose.yml that has the above service listed:
web:
build: ./client
environment:
- NODE_VERSION=$NODE_WEB_VERSION
ports:
- "4200:4200"
api:
And here's my simple bash script
#!/usr/bin/env bash
frontend=$1
backend=$2
git clone //remote_url --branch $frontend --single-branch
mv project-folder ~/
docker-compose up
But the issue is that the RUN npm run build gives error,
enoent ENOENT: no such file or directory, open '/home/ayush/project-folder/package.json'
What could be the issue?
You forgot to copy your project during build time, with
...
COPY . ./
RUN npm run build
...
This will copy the whole build context (the contents of ./client) to the working directory, which you've set to /home/ayush/project-folder in the previous statement.
I am working on integrating CI/CD pipeline using Docker. How can i use dockercompose file to build and create container?
I have tried it in putting Dockerfile, and docker-compose.yml, but none of them works.
Below is docker-compose file :
FROM ruby:2.2
EXPOSE 8000
RUN mkdir -p /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN bundle install
CMD ["ruby","app.rb"]
RUN docker build -t itsruby:itsruby .
RUN docker run -d itsruby:itsruby
Below is docker-compose.yml
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.2
steps:
- checkout
- run: CMD ["ruby","app.rb"]
- run: |
docker build -t itsruby:itsruby .
docker run -d itsruby:itsruby
test:
docker:
- image: circleci/ruby:2.2
steps:
- checkout
- run: CMD ["ruby","app.rb"]
The build is getting failed in circle/ci.