Docker Notes

Container Notes

A container is a instance of running image.

sudo docker container run --publish 80:80 nginx

sudo docker container run --publish 80:80 --detach nginx

sudo docker container ls

sudo docker container stop bab <-- only needs to be as long as unique

sudo docker container run --publish 80:80 --detach --name webhost nginx

sudo docker container logs webhost

Running a Rails app from Docker.

Sample Docker file for Running my Rails App

FROM fedora:32
RUN dnf install -y nodejs.x86_64
RUN dnf install -y nodejs-devel.x86_64
RUN dnf install  -y gcc g++ make
#RUN dnf install -y  mariadb.x86_64
RUN dnf install -y rubygem-sqlite3.x86_64
RUN cd /opt
RUN mkdir MyApp
COPY ./ /opt/MyAPP/
WORKDIR /opt/MyApp

FROM ruby:2.6.3
RUN gem update --system
RUN gem install rails -v 5.2.3
RUN gem install bundle
RUN gem update --system
RUN bundle install
ENV RAILS_ENV=development
RUN rails db:schema:load # Note migrations got large, so transferred most to the schema. 
RUN rails db:migrate
RUN rails db:seed #load existing data
CMD ["rails", "server", "-b","0.0.0.0"]
$> cd MyApp
$> docker image build  -t myApp-init .   ← will run the requests in the docker file
$> docker run --detach --publish 3000:3000 --name my-app myApp-init

listing running containers:-

$> docker ps

Listing existing containers

$> docker container ls  (or -a for all, including stopped)

Listing available docker images

$> docker image ls (or -a for sub images?)

Other useful

$>docker start my-app
$>docker stop my-app
$>docker container rm b8fbabf2e771 40c986ecbfe1 2413da657642 502a491735ed
$>docker run --it --publish 3000:3000 --name my-app myApp-init /bin/bash <- will dump you into bash window to help diagnose bugs
$>docker logs my-app