4 posts

Simple alternative to nvm using Docker

After Node v6.6.0 is out, I wanted to try it, but I don't want to replace my local Node v4 environment. I can use nvm, but that's too much for some simple tests. So I switched to Docker.

Just adding following alias to my .zshrc file, I can now run JavaScript file using Node 6.

alias node6="docker run -it --rm -v $(pwd):/code -w /code node:6.6 node"  
node6 hello.js  

I also added Node 4.

alias node4="docker run -it --rm -v $(pwd):/code -w /code node:4.5 node"  

Docker build apt-get install error

I was trying to build a docker image and use apt-get to install packages and kept getting this error Error reading from server. Remote end closed connection for different packages. The reason is because server tries to return different server mirrors for different packages and some servers may have temporary load or connection issues. I tried a couple of solutions, e.g. run apt-get clean doesn't work, add --no-cache to docker build doesn't work. The only workable solution is to add following line to Dockerfile before run apt-get install.

RUN sed -i "s/`curl -s -D - | awk '/^Link:/ { print $2 }' | sed -e 's@<http://\(.*\)/debian/>;@\[email protected]'`/" /etc/apt/sources.list  

Thanks to this SO answer.

Docker - Clean up disk space

When using Docker Toolbox on Mac OS X, it complains no space left on device after a while. So we need to clean up the disk space.

Delete exited containers

docker rm -v $(docker ps -a -q -f status=exited)  

Remove dangling images

docker rmi $(docker images -f "dangling=true" -q)  

Remove dangling volumes

docker volume rm $(docker volume ls -qf dangling=true)  

References: 1, 2

AWS Elastic Beanstalk - No carriage returns in Dockerfile

AWS Elastic Beanstalk has a very good Docker support. But for Dockerfile, you need to make sure no carriage return (CR) is in the Dockerfile, only line feed (LF) should be used. Otherwise, you may find weird issues.

For example, a simple Dockerfile as below,

FROM ubuntu:14.04  

If a CR is the last character in first line, Beanstalk will have error like repository not found ubuntu:14.04. This is because Beanstalk uses ubuntu:14.04<CR> as the repository name. So CR cannot be used in Dockerfile.

On Windows platform, Notepad++ can be used to find CR and remove them.