I'm probably doing something very wrong, but I'll ask here just in case since I can't find it. Basically, I have no problem running my docker image when I'm on my pc and I just do "Docker-compose run..." from within the ruby app directory. However, when I push the image to the docker-hub, I want to pull that image on my ubuntu server to then build that image. The problem is that when I do so, I don't really have access to the ruby app, the gemfile or anything so it doens't work at all...
This was my error :
Step 10/23 : COPY Gemfile /myapp/Gemfile COPY failed: stat /var/lib/docker/tmp/docker-builder296802662/Gemfile: no such file or directory
My Dockerfile :
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update -qq && apt-get install -y nodejs yarn netcat libpq-dev nano tzdata apt-transport-https
RUN apt-get clean autoclean
RUN rm -rf /var/lib/apt /var/lib/dpkg /var/lib/cacbe /var/lib/log
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile Gemfile.lock /myapp/
RUN bundle install
COPY . .
RUN rm -Rf node_modules/
RUN rm yarn.lock
RUN spring stop
RUN rails webpacker:install
RUN yarn install
RUN yarn upgrade
RUN yarn install --check-files
EXPOSE 3000
# Running the startup script before starting the server
ENTRYPOINT ["sh", "./config/docker/startup.sh"]
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
My docker-compose :
services:
db:
image: mysql:latest
restart: always
command: --default-authentication-plugin=mysql_native_password
# volumes:
# - ./tmp/db:/var/lib/postgresql/data
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test
MYSQL_USERNAME: root
MYSQL_PASSWORD: root
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
links:
- db
environment:
DB_USER: root
DB_NAME: test
DB_PASSWORD: root
DB_HOST: db
DB_PORT: 3306
RAILS_ENV: development
How am I supposed to make it so that on my ubuntu server I can simply pull the image from my repo, build and run it?
Thank you very much.
P.S. I also always get "Your Yarn packages are out of date!"...
If you've pushed your application images to Docker Hub, you need to, all in the web service:
Add the image: name of your Docker Hub image
Remove the build: section
Delete the volumes: that overwrite the image's code
Delete the command: overriding the image's CMD (consider adding the rm -f server.pid command to your startup.sh entrypoint script)
Delete the archaic links: setting
This leaves you with:
version: '3.8'
services:
db: *as_in_the_question
web:
image: 'myname/web:20200622'
ports:
- "3000:3000"
depends_on:
- db
environment:
DB_USER: root
DB_NAME: test
DB_PASSWORD: root
DB_HOST: db
DB_PORT: 3306
RAILS_ENV: development
On the remote system you need to copy only the docker-compose.yml file, and you should be able to run docker-compose up to start it; it will pull the Docker Hub image and run it.
On the local system, if you have both a build: and an image: setting, docker-compose build will tag the image with the name you specify, and docker-compose push will push the built image.
Related
When I'm running Docker Compose up, I receive an error
** (Mix) The task "phx.server" could not be found
Note no mix.exs was found in the current directory
I believe it's the very last step I need to run the project. This is a phoenix/Elixir Docker project. Mix.exs is a top level file in my project, same level as my dockerfile/docker-compose file.
Dockerfile
FROM elixir:1.13.1
# Build Args
ARG PHOENIX_VERSION=1.6.6
ARG NODEJS_VERSION=16.x
# Apt
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y apt-utils
RUN apt-get install -y build-essential
RUN apt-get install -y inotify-tools
# Nodejs
RUN curl -sL https://deb.nodesource.com/setup_${NODEJS_VERSION} | bash
RUN apt-get install -y nodejs
# Phoenix
RUN mix local.hex --force
RUN mix archive.install --force hex phx_new #{PHOENIX_VERSION}
RUN mix local.rebar --force
# App Directory
ENV APP_HOME /app
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
COPY . .
# App Port
EXPOSE 4000
# Default Command
CMD ["mix", "phx.server"]
Docker-compose.yml
version: "3"
services:
book-search:
build: .
volumes:
- ./src:/app
ports:
- "4000:4000"
depends_on:
- db
db:
image: postgres:9.6
environment:
POSTGRES_DB: "db"
POSTGRES_HOST_AUTH_METHOD: "trust"
POSTGRES_USER: tmclean
POSTGRES_PASSWORD: tmclean
PGDATA: /var/lib/postgresql/data/pgdata
restart: always
volumes:
- ./pgdata:/var/lib/postgresql/data
Let me know what other questions I can answer
The problem is your docker-compose.yml file.
volumes:
- ./src:/app
You are overwriting the app with a probably non-existant src directory. Change it to:
volumes:
- .:/app
and it should work. However, if you do that, there is no point in copying the files in your Dockerfile, so you can also remove the
COPY . .
Alternatively, leave the COPY if you want the source files to be in the image, and remove the volumes section from the book-search service in docker-compose.yml.
I have a very basic rails & docker app that I want to add Angular to, to handle all my frontend javascript. However, I can't seem to get Angular to work. I installed Angular via webpacker. As of now I only have the hello-angular files that come standard with rails 6 and webpack.
Dockerfile
FROM ruby:2.6
# Prerequisites
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && apt-get update -q && apt-get install -y nodejs yarn cron
# Cache Gems
WORKDIR /tmp
ADD Gemfile .
ADD Gemfile.lock .
RUN bundle install
# Copy App
WORKDIR /usr/bcb/app
ADD . /usr/bcb/app
# Precompile assets
RUN bin/yarn install
RUN bin/rails assets:precompile
# Expose port 3000 to other containers (Note: not external devices such as our workstation)
ENV PORT 3000
EXPOSE $PORT
# Run the built in Rails server (puma)
CMD ./docker-entrypoint.sh
# clean up APT
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
docker-compose.yml
version: '3.3'
volumes:
dbdata:
driver: local
services:
nginx:
image: nginx
ports:
- '8080:80'
volumes:
- ./nginx/vhost.development.conf:/etc/nginx/conf.d/default.conf
restart: always
depends_on:
- web
db:
image: postgres:11
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=devdb
volumes:
- dbdata:/var/lib/postgresql/data/pgdata
web:
build: . # Builds the image from Dockerfile
environment:
WEBPACK_DEV_SERVER_HOST: webpack_dev_server
links:
- webpack_dev_server
environment:
- RAILS_ENV=development
- RACK_ENV=development
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=devdb
volumes:
- .:/usr/bcb/app
depends_on:
- db
webpack_dev_server:
image: bcbapp_web
command: ./bin/webpack-dev-server
environment:
NODE_ENV: development
RAILS_ENV: development
WEBPACK_DEV_SERVER_HOST: 0.0.0.0
volumes:
- .:/usr/bcb/app
ports:
- "3035:3035"
docker-entrypoint.sh
rm -f tmp/pids/server*.pid
bin/rails server -b 0.0.0.0 -p $PORT --pid tmp/pids/server.`hostname`.pid
bundle exec rake db:migrate RAILS_ENV=$environment 2>/dev/null || bundle exec rake db:create db:migrate
Here is my github repo:
[1]: https://github.com/zacwillis/bcb
What am I missing?
I am trying to Dockerize my Rails 6 app but seem to be falling at the last hurdle. When running docker-compose up everything runs fine until i get to "Attaching to rdd-ruby_db_1, rdd-ruby_web_1" in the console and then I get the error bash: bundle: command not found.
I am aware of the other answers on Stackoverflow for the same issue but i have tried all before posting this.
My Dockerfile:
FROM ruby:2.7
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN cd /usr/bin/
RUN bundle install
FROM node:6.7.0
RUN npm install -g yarn
COPY . /myapp
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["/usr/bin/entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
My docker-compose
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: xxx
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
I originally followed the guide in the Docker documentation thinking this would work over at https://docs.docker.com/compose/rails/
Thanks.
I'm having problems with a project, using docker-compose, I always use the same Dockerfile and docker-compose.yml in all projects, just changing the version of ruby. However, in just ONE of these projects, I no longer update what I modify in the code, every change I make always reflected, but now it stopped suddenly, and only in one project. I have already refitted build, I have removed all the containers, all the images, downloaded the project again ... and nothing! Just refresh if I stop and upload the container again!
docker-compose.yml :
version: '2'
services:
postgres:
image: 'postgres:9.5'
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- postgres
Dockerfile
FROM ruby:2.3.1
RUN apt-get update -qq && apt-get install -y build-essential libpq- dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
ADD . /myapp
Resolved, in config/environments/development.rb it has to be: config.cache_classes = false
I'm trying to setup docker for a existing QuorraJs application.
(https://quorrajs.org/docs/v1/preface/quickstart.html) however i'm having issues when trying to run docker-compose build.
I am still quite new to docker, not sure what i am doing wrong.
docker file
FROM node:latest
MAINTAINER Erkan Demir <erkan.demir#peopleplan.com.au>
#Add everything in the current directory to our image
ADD . /var/www
RUN cd /var/www; \
npm install \
npm install -g quorra-cli \
EXPOSE 3000:3000
CMD["quorra ride"]
docker-compose.yml
version: '2'
services:
web:
container_name: quorra-web
build: .
ports:
- '3000:3000'
volumes:
- .:/var/www
links:
- db
depends_on:
- db
db:
container_name: quorra-db
image: mysql
ports:
- '3000:3000'
volumes:
- /var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: Petbarn_DB
MYSQL_USER: root
MYSQL_PASSWORD: password
Apparently there are some things wrong in your Dockerfile, try running it as follows:
FROM node:latest
MAINTAINER Erkan Demir <erkan.demir#peopleplan.com.au>
#Add everything in the current directory to our image
ADD . /var/www
RUN cd /var/www/ && \
npm install && \
npm install -g quorra-cli
EXPOSE 3000
CMD['quorra', 'ride']
Try adding && and remove last \ in your Dockerfile:
...
RUN cd /var/www; \
npm install \
&& npm install -g quorra-cli
...