Skip to content

Instantly share code, notes, and snippets.

@lorenadl
Last active June 11, 2018 09:18
Show Gist options
  • Save lorenadl/0d8499ce290fb1ba7e9bbb6473ddb6d3 to your computer and use it in GitHub Desktop.
Save lorenadl/0d8499ce290fb1ba7e9bbb6473ddb6d3 to your computer and use it in GitHub Desktop.
[ROR] Docker for Rails applications
Docker
-------------------------
Se lanciando
> docker images
o
> docker-compose up --build
dà questo errore:
error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.36/images/json: open //./pipe/docker_engine: Impossibile trovare il file specificato. In the default daemon configuration on Windows,
the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.
Manca la macchina virtuale di docker:
> docker-machine create box
Per controllare:
> docker-machine env box
Ora dovrebbe funzionare nella shell del toolbox.
Se non funziona nelle shell normali (cmd):
> docker-machine env --shell cmd box
> @FOR /f "tokens=*" %i IN ('docker-machine env --shell cmd box') DO @%i
-----------------
https://nickjanetakis.com/blog/dockerize-a-rails-5-postgres-redis-sidekiq-action-cable-app-with-docker-compose
-----------------
Per conoscere l'ip della macchina docker:
> docker-machine ip
------------------------------
Come usare una macchina linux (grafica e cmd) da windows 10 qualsiasi versione
https://nickjanetakis.com/blog/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows
------
https://docker-curriculum.com/#dockerrun
delete all exited containers
$ docker rm $(docker ps -a -q -f status=exited)
$ docker run prakhar1989/static-site
$ docker run -d -P --name static-site prakhar1989/static-site
$ docker port static-site
-------------------------------
RAILS
https://docs.docker.com/compose/rails/#build-the-project
ATTENZIONE: il docker-compose NON funziona se i sorgenti non sono in una sottocartella di c:/Users!!!
https://github.com/docker/compose/issues/2103
se dice "server already running":
> rm tmp/pids/server.pid
Per lanciare i programmi rails mentre docker sta girando:
docker-compose run web rake db:create
docker-compose run web rails g controller Welcome

Docker for Rails applications

https://codepany.com/blog/rails-5-and-docker-puma-nginx/

Per far funzionare byebug:

https://stackoverflow.com/questions/31669226/rails-byebug-did-not-stop-application/32690885#32690885

Add this to docker-compose.yml

web:
  ...<br>
  stdin_open: true<br>
  tty: true

Then run docker-compose in deamonized mode and attach to the web container with docker:

docker attach myappname_web_1

Note that it's not necessary to run your services in detached mode. Also when you attach to the container, it'll appear as if it's hanging, but as soon as that container's app receives a request, you'll see logger output.

Do not use docker attach myappname_web_1. Instead, run "docker container ls" to get the containers running, and then find the id of the one you are working on. Then, just run: "docker attach container_id"

docker exec -it <containerIdOrName> bash

Basically if the docker container was started using /bin/bash command you can access it using attach, if not then you need to execute the command to create a bash instance inside the container using exec

Also to exit bash without leaving bash running in a rogue process

exit

Comandi principali

Nella cartella dell’applicazione (dove c’è il file docker-compose.yml):

$ docker-compose build

Run container(s)

$ docker-compose up

Con detach:

$ docker-compose up –d

‘Attaccarsi’ ad un container:

$ docker attach process_id

Esempio:

$ docker attach 9f4a2089327a

process_id: lo vedi con $ docker ps

Stop container(s)

$ docker-compose stop

Eseguire un comando nel container:

$ docker exec –it container_name c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment