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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • 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. “docker logs” Command Examples
  2. kubectl: command not found
  3. How to Run Ad-Hoc Commands Using Ansible
  4. Backtick (`) symbol in Linux Shell Scripting
  5. Examples of creating command alias in different shells
  6. “docker service” Command Examples
  7. How to Start, Stop and Restart Zimbra Service
  8. Windows Subsystem For Linux – Run Linux on Windows (It’s FAST)
  9. “docker machine” Command Examples
  10. aws-shell: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright