Docker Debian locales installation

Problem

You want to install some default locales in a Docker image, and the suggestion is to use locale-gen to do so, but it does not work as expected.

Solution

In order to be able to use the locale-gen and install the locales you need you will have to uncomment the ones needed from /etc/locale.gen first and then use the locale-gen. Example below:

## Set up locales
## Uncomment the ones we need as locale-gen does not work without that
RUN sed -i '/en_US.UTF-8/s/^#//' /etc/locale.gen
RUN sed -i '/de_DE.UTF-8/s/^#//' /etc/locale.gen
## Now install them and set the default one
RUN locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

Dockercloud-agent error: …Error creating default \”bridge\” network:…

Problem

When trying to use the dockercloud-agent with docker you have the following error in the /var/log/dockercloud/agent.log

level=fatal msg="Error starting daemon: Error initializing network controller: Error creating default \"bridge\" network: cannot create network xxx... (docker0): conflicts with network yyy.... (docker0): networks have same bridge name" 

Solution

If you remove the file var/lib/docker/network/files/local-kv.db as suggested here, then if you look again at the log files, it should be a message that the docker daemon has been started:

016/11/17 10:30:28 Respawning docker daemon
2016/11/17 10:30:28 Starting docker daemon: [/usr/bin/docker daemon -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 --userland-proxy=false --tlscert /etc/dockercloud/agent/cert.pem --tlskey /etc/dockercloud/agent/key.pem --tlscacert /etc/dockercloud/agent/ca.pem --tlsverify]
2016/11/17 10:30:28 Docker daemon (PID:4036) has been started

Clearing unused (dangling) docker volumes

Problem

After you start using and building Docker images, there is a case that there is a lot of space used even after deleting images and containers (a few GB maybe).

Solution

To clean out the volumes that are no longer used (ie dangling) use the following:

sudo docker volume ls -qf dangling=true | xargs -r sudo docker volume rm

Error response from daemon: conflict: unable to delete xxx (must be forced) – image is referenced in one or more repositories

Problem

Trying to remove some unused docker images that you no longer use with docker rmi image_id you get the following error message:

Error response from daemon: conflict: unable to delete 75d009de0479 (must be forced) - image is referenced in one or more repositories

Solution

Use the following to delete multiple images (ie ubuntu):

docker images ubuntu | tail -n +2 | awk '{ print $1 ":" $2 }' | xargs sudo docker rmi

Mentioned here

Starting Phoenix server in a different port than 4000

Problem

You would like start a phoenix application in a port different from the default 4000, by using something similar to the rails:

rails s -p 4001

Solutin

You will need to change the config/dev.exs file to include the following:

http: [port: System.get_env("PORT") || 4000],

and then start the server with:

PORT=4002 mix phoenix.server

Taken from the answer here

Routing rspec with nested routes

Problem

You would like to add a routing rspec test in your rails application that tests for a nested route.
So while you have something like the following in your config/routes.rb file:

namespace :admin do
  resources :users do
    resources :audits, only: [:index]
  end
end

you want to add the following test for your route:

expect(get: '/admin/users/:user_id/audits').to route_to(controller: 'admin/audits', action: 'index')

but you are getting an error like the following:

The recognized options <{"controller"=>"admin/audits", "action"=>"index", "user_id"=>":user_id"}> did not match <{"controller"=>"admin/audits", "action"=>"index"}>, difference:.
       --- expected
       +++ actual
       @@ -1 +1 @@
       -{"controller"=>"admin/audits", "action"=>"index"}
       +{"controller"=>"admin/audits", "action"=>"index", "user_id"=>":user_id"}

Solution

You will need to change your rspec to the following using any number for the user_id:

expect(get: '/admin/users/42/audits').to route_to(controller: 'admin/audits', action: 'index', user_id: '42')

Solution adapted from here

Removing git branches from local repository

Problem

You would like to remove your local branches that were used to track remote branches that no longer exists (deleted after merge).

git branch -a
branch_to_delete
remotes/origin/branch_to_delete

Solution

To delete your local branch you could use the following:

git branch -D branch_to_delete

And to to delete the remote tracking branching you could use the following:

git branch -rd origin/branch_to_delete