• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Access Docker Container’s Network Namespace from Host

by admin

This post is to illustrate how to access the docker container’s network namespace.

1. Identify the docker container id you want to access and run below command as root on host.

# docker ps

2. Get docker container’s PID:

# pid=$(docker inspect -f '{{.State.Pid}}' ${container_id})

3. Create netns directory:

# mkdir -p /var/run/netns/

4. Create the name space softlink:

# ln -sfT /proc/$pid/ns/net /var/run/netns/[container_id]

5. Run ip netns command to access this name space. For example:

# ip netns exec [container_id] ip a

Filed Under: DevOps, Docker

Some more articles you might also be interested in …

  1. Understanding Positional Parameters (Passing Parameters/Arguments to Shell script)
  2. Docker Troubleshooting – “conflict: unable to delete, image is being used by running container”
  3. How to add new host entry in /etc/hosts when a docker container is run
  4. The Ultimate Guide To Use VS Code With Windows Subsystem for Linux (WSL)
  5. The Ultimate Beginner’s Guide to Static Website Hosting With Google Firebase (for FREE)
  6. “while” Loop Examples in Shell Scripts
  7. Introduction to sed (Stream Editor) : Useful sed Command Examples
  8. How to use shell aliases in Linux
  9. How to use command redirection under Linux
  10. How to Download Ext JS GPL

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright