This is another post in docker series, In this article we will How to set Docker Name and Hostname while creating it.

SetUP

For this setup we are using Ubuntu 16.04 LTS latest as of now Dec 2017.

root@jarvis:~# lsb_release -d
Description:	Ubuntu 16.04.3 LTS

root@jarvis:~# uname -r
4.4.0-101-generic

root@jarvis:~# docker --version
Docker version 1.13.1, build 092cba3

For this setup we are going to use centos latest image to create docker container.

Syntax

So to create container with desired name, we need to use docker run command like below syntax.

docker run --name Given-name --hostname docker-Hostname  image 

In above command, we used –name to manage docker name used within Host docker process. –hostname used to assign hostname within Docker container. Example below.

root@jarvis:~# docker run --hostname centos7-docker  --name centos -it centos /bin/bash

Docker Hostname
[root@centos7-docker /]# hostname
centos7-docker

Docker Name
root@jarvis:~# docker ps -a
CONTAINER ID   IMAGE     COMMAND       CREATED          STATUS         PORTS    NAMES
98bf941c06b8   centos    "/bin/bash"   14 seconds ago   Up 13 seconds           centos

In Above example we had used docker run command to manage Docker container Hostname and Name

Some other Docker Posts
1. Docker Introduction
2. How To Work On Docker Container
3. How to Move Docker Image
4. How To Commit Container changes
5. Port Forwarding for Docker Container through IPTables
6. How To Share Data between Docker Container