Showing posts with label apt-get. Show all posts
Showing posts with label apt-get. Show all posts

Friday, August 5, 2016

Working with Docker Containers

Install Docker Containers:


We can install Docker containers in two different ways, One is to install the same with the yum package manager directly or second method is we can use curl with the get.docker.com site. We will be using yum this time.

1.  Log into our machine as a user with sudo or root privileges.
2.  Make sure our server existing yum packages are up-to-date.
# yum update

3. Add the yum repo:
# vim /etc/yum.repos.d/docker.repo
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg

Install the Docker package.
# yum install docker-engine

After, Docker package has been installed, start the daemon, check its status and enable it system wide using the below commands:
# systemctl start docker
# systemctl status docker
# systemctl enable docker

Verify docker is installed correctly by running a test image in a container.
# docker run hello-world
Unable to find image 'hello-world:latest' locally
    latest: Pulling from hello-world
    a8219747be10: Pull complete
    91c95931e552: Already exists
    hello-world:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security.
    Digest: sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d
    Status: Downloaded newer image for hello-world:latest
    Hello from Docker.
    This message shows that your installation appears to be working correctly.

    To generate this message, Docker took the following steps:
     1. The Docker client contacted the Docker daemon.
     2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
            (Assuming it was not already locally available.)
     3. The Docker daemon created a new container from that image which runs the
            executable that produces the output you are currently reading.
     4. The Docker daemon streamed that output to the Docker client, which sent it
            to your terminal.

Now, you can run a few basic Docker commands to get info about Docker:

For system-wide information on Docker
# docker info
# docker version

4. In order to start and run a Docker container, first an image must be downloaded from Docker Hub on your host. Docker Hub offers a great deal of free images from its repositories.
To search for a Docker image, Ubuntu for instance, issue the following command:
# docker search ubuntu

5.  We want to run Ubuntu, So download it locally by running the below command
# docker pull ubuntu

6. To list all the available Docker images on your host issue the following command:
# docker images

7. In order to create and run a container, you need to run a command into a downloaded image, in this caseUbuntu, so a basic command would be to display the distribution version file inside the container using cat command, as in the following example:

# docker run ubuntu cat /etc/issue

8. To run one of the containers again with the command that was executed to create it, first you must get the container ID (or the name automatically generated by Docker) by issuing the below command, which displays a list of the running and stopped (non-running) containers:

# docker ps -l

9. Once the container ID has been obtained, you can start the container again with the command that was used to create it, by issuing the following command:
# docker start <Container ID>

10. In order to interactively connect into a container shell session, and run commands as you do on any other Linux session, issue the following command:
# docker run -it ubuntu bash


11. To quit and return to host from the running container session you must type exit command. The exit command terminates all the container processes and stops it.
# exit

12. To reconnect to the running container you need the container ID or name. Issue docker ps command to get the ID or name and, then, run docker attach command by specifying container ID or name, as illustrated in the image above:
# docker attach <container id>


 

Install Apache Web server in Docker container



Once I start the new docker container as describe earlier, I will start two new containers for my Apache and Mysql deployment
# docker start <Container ID>
# docker run -it ubuntu bash

Once you are in the Ubuntu docker container, install the apache packages
# apt-get update && apt-get install apache2
Now its time to start the service,
# /etc/init.d/apache2 start
To verify if the server is running, try using links command. (We might need to install it if thats not available.
# apt-get install links  (if links command is not installed)
# links http://127.0.0.1
To store the current state of the Docker containers, we need to commit them, so that they start with your configuration next time when you start them by 'exit' command.
# docker commit <container ID> yogesh/apache
Install MySQL server in Docker container

In other TAB, we can start one more Docker container for Mysql server
# apt-get update
# apt-get install mysql-server
(Type password when asked for Mysql database password)
After mysql is installed, start the service:
# /etc/init.d/mysql start
Try and test it out:
# mysql -u root -p
(Type password)
> show databases;
(Displays all default databases)
>exit
(To exit out of server)
Default Logs for mysql are saved in  /var/log/mysql/error.log
To store the current state of the Docker containers, we need to commit them, so that they start with your configuration next time when you start them after the 'exit'.
# docker commit <container ID> yogesh/mysql

You can view the complete procedure in below video:


Monday, August 10, 2015

Working with apt-get and dpkg package manager tools of 'Debian'



First of all we are going to work with Apt-get package manager. For those who are already familiar with Yum of Red Hat based distros may find this quite identical tool. Apt-get pulls and installs packages from the online repository to ease your pain to find, download and install packages and its dependency manually.

You have to be root using for the following hands-on, Let's get started:

root@yogeshkk21:~# apt-get update

This command pulls package information from repository server and caches the same locally

root@yogeshkk21:~# apt-cache search nginx

We can search for a specific package in the entire cache using this command


root@yogeshkk21:~# apt-get install nginx

This command is to install a package

root@yogeshkk21:~# which nginx

To verify nginx is installed

root@yogeshkk21:~# apt-cache search apache2

Let's search for Apache2 package as well

root@yogeshkk21:~# apt-get install apache2

And Install it same as nginx

root@yogeshkk21:~# apt-get remove ngnix

Now, let's learn How to remove it

root@yogeshkk21:~# apt-get remove --purge nginx

apt-get remove only removes the binary, but keeps associated library and configuration files. So to remove everything, use purge.

root@yogeshkk21:~# apt-get autoremove

This command removes unnecessary packages alongside the removed package

root@yogeshkk21:~# which ngnix

Let's verify

root@yogeshkk21:~# apt-get remove apache2 ; apt-get autoremove apache2

This removed apache2 package along with unnecessary packages of it

root@yogeshkk21:~# which apache2

Let's verify again

root@yogeshkk21:~# apt-get install apache2

Let us install apache2 package again

root@yogeshkk21:~# apt-get upgrade

This command allows you to upgrade any packages required for apache2

root@yogeshkk21:~# apt-get dist-upgrade

This command allows you to upgrade distribution kernel if available

Now if we talk about dpkg package manager, it's the little bit different from the apt-get. This does not pull the dependencies automatically like apt-get does. Let's see:

root@yogeshkk21:~# wget https://www.dropbox.com/download?dl=packages/ubuntu/dropbox_2015.02.12_amd64.deb

Let's try to install Dropbox application on our Ubuntu 12.04 distro.

root@yogeshkk21:~# mv download\?dl\=packages%2Fubuntu%2Fdropbox_2015.02.12_amd64.deb dropbox.deb

Let's rename this downloaded file to something more simple.

root@yogeshkk21:~# dpkg -i dropbox.deb

To install the Deb file, use -i option. Now you will see that lots of dependency errors are been thrown at you. Its simply because, dpkg can't pull all those dependency for you. So, what now? Should I download and install them manually? No, there is a way out.

root@yogeshkk21:~# apt-get update

Let's update our cache once again

root@yogeshkk21:~# apt-get -f upgrade

And this command will do the job for us. It automatically pulls all the required library packages along with other dependencies. Nice, right?

root@yogeshkk21:~# dpkg -i dropbox.deb

Now, let's try that deb file again for installation. And you will notice, it gets installed! :)

root@yogeshkk21:~# which dropbox

Let's verify! Worked well.

root@yogeshkk21:~# dpkg --get-selections

Now let's also find out, how can we list all installed packages. This command will do the magic for us.

root@yogeshkk21:~# dpkg --get-selections  |grep -i dropbox

We can find specific package name from the output using grep.

root@yogeshkk21:~# dpkg --remove dropbox

Just like apt-get we have remove command as well in dpkg and it removes all binary for us.

root@yogeshkk21:~# dpkg --purge dropbox

To remove the application completely, using this command.

So that's how we can use apt-get and dpkg.

HTH ^_^

Above command is tested and worked on:

root@yogeshkk21:~# lsb_release -a
No LSB modules are available.
Distributor ID:    Ubuntu
Description:    Ubuntu 12.04.5 LTS
Release:    12.04
Codename:    precise