- Create the project structure
docker run -it --rm -v ${PWD}:/usr/src/app -w /usr/src/app ruby:3.1.2 bash -c 'gem install rails && rails new trader-bot -T -d mysql -c tailwind'
- /<project_name>/Dockerfile
wget https://github.com/jmscarnatto/dockerfile-rails7/raw/main/Dockerfile
FROM ruby:3.1.2
ENV HOME=/application
# INSTALL APT DEPENDENCIES
RUN apt-get update -qq && apt-get upgrade -y && apt-get install -y --no-install-recommends build-essential git \
ssh wget curl systemctl apt-utils redis-server libssl-dev libcurl4-openssl-dev python3 shared-mime-info zlib1g-dev sudo \
readline-common imagemagick pdftk memcached dnsutils gnupg less vim default-libmysqlclient-dev keychain htop inetutils-ping python2 \
zsh ncdu
# CLEANING APT CACHE
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
WORKDIR $HOME
ENV BUNDLE_PATH /gems
COPY Gemfile Gemfile.lock $HOME/
RUN gem install rails webpacker
RUN bundle install
COPY . $HOME
# OH-MY-ZSH
RUN wget -P $HOME https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh; \
sh $HOME/install.sh; \
rm $HOME/install.sh
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting --depth 1 \
# Download zsh-autosuggestions
&& git clone https://github.com/zsh-users/zsh-autosuggestions $HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions --depth 1 \
# Download powerlevel10k
&& git clone https://github.com/romkatv/powerlevel10k.git $HOME/.oh-my-zsh/custom/themes/powerlevel10k --depth=1 \
# Download powerlevel10k config
&& curl -sLo $HOME/.p10k.zsh https://raw.githubusercontent.com/Favna/dotfiles/main/.p10k.zsh
RUN sed -i 's/robbyrussell/powerlevel10k\/powerlevel10k/' $HOME/.zshrc && \
sed -i 's/(git)/(git zsh-autosuggestions zsh-syntax-highlighting)/' $HOME/.zshrc && \
echo "[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh" >> $HOME/.zshrc
ENTRYPOINT ["bin/rails"]
CMD ["s", "-b", "0.0.0.0"]
EXPOSE 3000
EXPOSE 3050
- /<project_name>/docker-compose.yml
services:
www:
build: .
container_name: example1-web
volumes:
- .:/application
ports:
- "3002:3000"
- "3050:3050"
environment:
RAILS_ENV: development
RAILS_MAX_THREADS: 5
SRC_DATABASE_USERNAME: ${SRC_DATABASE_USERNAME}
SRC_DATABASE_PASSWORD: ${SRC_DATABASE_PASSWORD}
SRC_DATABASE_HOST: ${SRC_DATABASE_HOST}
- /<project_name>/.env
SRC_DATABASE_USERNAME=<username_here>
SRC_DATABASE_PASSWORD=<password_here>
SRC_DATABASE_HOST=<host_ip_here>
- .dockerignore
touch .dockerignore
echo ".git \n node_modules" >> .dockerignore
- db:migrate
docker-compose run example1-web db:migrate
Reference: https://dev.to/linksake/docker-rails-una-solucion-para-tus-dolores-de-cabeza-jh8