Monday, July 31, 2017

Accessing MySQL Server from Docker Container.

For this example we will be using an image from Docker Hub.

You can list the available images by executing:

docker search mysql


and download it with:

docker pull mysql

If you want to list your local images, just type:

docker images



Now in order to create the container we can execute a command with the following options:

docker run -p <port>:<port> --name <container-name> -v <local-folder>:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=<root-password> -d mysql:<tag>

where:

-p Publish a container’s port(s) to the host
--name Assign a name to the container
-v Bind mount a volume
-e Sets the MYSQL_ROOT_PASSWORD environment variable
-d Run container in background and print container ID
tag Tag specifying the MySQL version you want.

Then if you want to see the containers currently running:

docker ps


But, How can I start working with the MySQL of the docker container?

Via terminal (accessing the container bash):

docker exec -it <container-name> bash


Or just pointing your favorite Database Client to the container configuration:






Sunday, July 23, 2017

How to show current Git Branch in the Terminal.

Adding (replacing) the following code to your .bashrc file will do the trick:

# Add git branch if its present to PS1

parse_git_branch() {
 git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi

How it looks your bash prompt:


See the original post here.